skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. @bobdye Answer has no effect for me, but this works:

    function wpseo_canonical_exclude($canonical) {
    if (is_paged()) {
        $canonical = false;
    }
    return $canonical;
    }
    add_filter( 'wpseo_canonical', 'wpseo_canonical_exclude' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search