Search code examples
wordpresscanonical-link

Yoast SEO plug-in removing canonical tag


I am currently using the wordpress seo plugin by yoast, and have run across a problem trying to remove the following tag:

    rel="canonical"  

The canonical tag is ok on a page such as blog.com/page/, however, on pages such as blog.com/page/2/ I don't want the canonical tag to show up.

I've done some googling and haven't been able to find quite what i'm looking for so im hoping stack overflow will save the day.


Solution

  • The WordPress SEO plugin has a filter you can use to disable the canonical URL on the pages you mention above.

    In your functions.php file, add:

    if (is_paged()) {
        add_filter( 'wpseo_canonical', '__return_false' );
    }
    

    The WordPress function is_paged() returns true if the page being displayed is "paged" and the current page number is greater than one.

    Returning false to the filter disables it.