How to remove rel = “canonical” tag?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hello,

    Thank you for contacting Rank Math today.

    The canonical link tag is automatically added when your pages/posts are set to index. If I may ask, why do you wish to remove the canonical tag from your page?

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hi

    You can however use the following code on your theme’s functions.php file to remove Rank Math meta info apart from the title:

    add_action( 'wp_head', function(){
    	if( is_singular('enter_product_post_type_name_here')) {
    		remove_all_actions( 'rank_math/head' );
    		add_action( 'wp_head', '_wp_render_title_tag', 2 );
    	}
    }, 1 );

    Looking forward to helping you. Thank you.

    I have a very rare taxanomy structure – Hierarchical, of the three taxanomies. I need to remove this tag, because 2 taxanomies refer to the third and will not be indexed.

    Hello,

    Thank you for the follow up.

    In this case that you don’t want them to be indexed, I would recommend adding a NOINDEX tag. This can be done from Rank math advanced meta box.

    Looking forward to helping you. Thank you.

    ​​​​​​

    I want them to be indexed. To do this, I need to remove the <link rel = “canonical” tag …. . How to do it?

    remove_action(‘wp_head’,’rel_canonical’); – this does not work

    Please use this code in the theme’s functions.php file:

    add_action( 'wp_head', function(){
    	if( is_singular('enter_product_post_type_name_here')) {
    		remove_all_actions( 'rank_math/head' );
    		add_action( 'wp_head', '_wp_render_title_tag', 2 );
    	}
    }, 1 );

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Added this code but nothing has changed.

    Hello,

    Thank you for contacting Rank Math today.

    This code will not work on its own, you need to customize it further on this line to target the taxonomy page:
    if( is_singular('enter_product_post_type_name_here')) {

    Here is another snippet that you can use to only remove the canonical and not the rest of the Rank Math meta:

    /**
     * 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;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    Many thanks. It worked

    Hi,

    We are so glad to be of help. We are always here if you need us in the future.

    Hey, if it isn’t too much to ask for – would you mind leaving us a review here?

    https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post

    It only takes a couple of minutes but helps us tremendously.

    It would mean so much to us.

    Thank you.

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

The ticket ‘How to remove rel = “canonical” tag?’ is closed to new replies.