Remove the canonical tag from a page

#823809
  • Resolved yellowhite
    Rank Math free

    I have a page template that dynamically generates content pages from another source. Each source document has its own unique URL. For example, my base page is:

    example.com/delta/

    Using URL rewrites, this base URL doesn’t actually exist, but users can access specific pages such as:

    example.com/delta/topic1
    example.com/delta/topic2
    example.com/delta/topic3

    The page template at example.com/delta/ is used to populate these individual pages.

    However, the canonical tag from the base template is also being copied to the generated pages. How can I remove the canonical tag from these dynamically populated pages?

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

    To remove the canonical tag from dynamically generated pages in your scenario, you can follow these steps:

    1. Access the Page Template: Locate the page template that generates the dynamically populated pages from the base template at example.com/delta/.

    2. Remove the Canonical Tag: Within the page template code, search for the canonical tag that is being copied to the generated pages. It will look like this:

      Simply remove or comment out this line of code to prevent the canonical tag from being included on the dynamically generated pages.

    3. Update and Save: After removing the canonical tag from the page template, save the changes to the file.

    By following these steps, you should be able to remove the canonical tag from the dynamically populated pages generated from your base template at example.com/delta/.

    If you encounter any issues or need further assistance, please feel free to reach out for additional support.

    Thank you for reaching out with your question.

    Sources:
    Alternate Page with Proper Canonical Tag Status in Google Search Console Ā» Rank Math
    How to Fix ā€˜Duplicate Without User-Selected Canonical’ Status in Google Search Console Ā» Rank Math

    Hello,

    If you need to remove the canonical tag, then you can set them to noindex by this filter:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    $url = home_url( $_SERVER['REQUEST_URI'] );
    if( (strpos($url,'/delta/') !== false) ) {
    $robots["index"] = 'noindex';
    $robots["follow"] = 'nofollow';
    }
    return $robots;
    });

    However, if you wanted to set them to index and have a self-referencing canonical, you can add this filter instead:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	$url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    	if(strpos($url,'/delta/') !== false){
    		return $url;
    	}
    	
    	return $canonical;
    });

    And here’s a guide to adding the code to the website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how this goes.

    Perfect, this worked well!

    Hello,

    We are super happy that we have addressed 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 do 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 4 replies - 1 through 4 (of 4 total)

The ticket ‘Remove the canonical tag from a page’ is closed to new replies.