Remove Canonical tax from specific page

#204818
  • Resolved Ewa W
    Rank Math pro

    Hello,

    Something like 1 year before, Michael Davis gave the tip how to remove the canonical tag from specific page. The code is as follows:

    /**
    * Allow changing of the canonical URL.
    *
    * @param string $canonical The canonical URL.
    */
    add_filter( ‘rank_math/frontend/canonical’, function( $canonical ) {
    //create conditional here to check for the tax page
    if(condition){
    return ”;
    }
    return $canonical;
    });

    My question is – is this a right code to remove canonical from specific page (not whole taxonomy type)? And whre in this code can I insert the page url or id?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    To remove the canonical tag from the specific page, you need to put the below code inside your themes function.php file.

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
        //change the post id 123 with yours
            if(is_single ($post = '123') ){ 
                return '';
            }
    		
    	return $canonical;
    });

    I hope that helps. Thank you, and please don’t hesitate to contact us anytime if you need further assistance.

    Thank you so much

    Prabhat
    Rank Math agency

    Hello,

    We are super happy that we could address your concern. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Remove Canonical tax from specific page’ is closed to new replies.