[Solved][AMP Error] The tag ‘link rel=canonical’ appears more than once in the document.

We received a sudden rise of errors in Search Console with Error
“The tag ‘link rel=canonical’ appears more than once in the document”.
We are using the following two plugins:

This Error arose because both plugins were adding canonical to AMP Code. Removing one is the only solutions.

As Canonical from Yoast was wrong, we decided to remove Yoast’s Canonical. Thanks to Yoast team for the canonical documentation & wpseo_canonical Filter. Following Code is what we used to remove Canonical from AMP Output.

// Remove canonical from better-amp output.
add_filter( 'wpseo_canonical', 'remove_canonical_from_bamp' );
function remove_canonical_from_bamp( $canonical ) {
  if(is_better_amp()){ 
      return false;
  }
  return $canonical; /* Do not remove this line. */
}

Above code will work only if you are having Better AMP plugin in use.
Happy Publishing!

[Update] Based on Comments, Please Paste that function in your Theme’s Functions.php or if you are not sure how to edit Functions.php or use Code Snippets Plugin.

Comments

10 responses to “[Solved][AMP Error] The tag ‘link rel=canonical’ appears more than once in the document.”

  1. Joseph Avatar
    Joseph

    Hi Abhishek,

    Thanks a bunch!

    You saved me endless hours of embarking on a wild goose chase.

    Immediately I updated Yoast SEO plugin Google did not even take more than an hour before sending me notification about AMP issues based on The tag ‘link rel=canonical’ appearing more than once in the document.

    I am also having BetterAMP plugin so our experiences were both similar.

    Thank you for sharing this solution. It greatly helped me.

  2. saipavan Avatar
    saipavan

    Hi sir, where to paste this code reply me fast.

  3. sibghat ullah Avatar

    Hello Sir, I didnt understand. OK where should i paste the above code. Please explain in your article. There will be many people like me who are not that much techi.

  4. Montel Anthony Avatar

    Where will I put the code pls?

  5. Jake Avatar
    Jake

    Thank you Abhishek for this post. Coincidentally, these are the 2 plugins I’m using on my site.
    However, I don’t know where I will paste this code to remove the issue.
    Please help out.

  6. Abhishek Deshpande Avatar

    Hi @Jake,

    Paste that function in your Theme’s Functions.php

  7. Abhishek Deshpande Avatar

    Paste that function in your Theme’s Functions.php

  8. Abhishek Deshpande Avatar

    Paste that function in your Theme’s Functions.php

  9. Abhishek Deshpande Avatar

    Paste that function in your Theme’s Functions.php

  10. karamveer Avatar

    Thanks, I have solved problems with the help of your article.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.