Fixing Duplicate Canonical Link Element in WordPress

If you work with WordPress blogs and websites you will, no doubt, have had lots of fun over the years with duplicate content and spent plenty of time trying a) get it out of Google’s index and/or b) stopping it getting in there in the first place.

The introduction of support for the canonical link element by Google and the other search engines offered a powerful addition to the ways in which duplicate content can be suppressed. The canonical link element and its use has been widely discussed in the blogosphere so I won’t go into it here. Check out Matt Cutts’ Canonical Link Element in 5 minutes blog post for a good explanation if you don’t know about it already.

Back to WordPress. The two popular SEO plugins Platinum SEO Pack and All-in-one SEO Pack have supported addition of canonical link elements to posts and pages for a while now. I noticed recently that on a couple of my new sites using WordPress 2.9.2 there were duplicated canonical link elements in the header: –

<link rel=’canonical’ href=’‘ />

which had been added by WordPress and, a bit further down: –

<link rel=”canonical” href=”” />

in the Platinum SEO pack section.

Further investigation revealed that WordPress has supported the canonical link element and added this by default to all posts and pages since version 2.9.0. Now, I don’t know for sure if this is a bad thing, but intuition suggests that duplicated meta data in the header of a Web page won’t make a search engine think it’s a better quality page than if that data was only specified once. So, how to get rid of the duplicates?

It’s easy. Either a) turn off “canonical URLs” in your SEO plugin or b) comment out the following line in wp-includes/default-filters.php: –

add_action( ‘wp_head’, ‘rel_canonical’ );

Personally, I commented out the bit of the WordPress script. After all, the SEO plugin writers thought if it first.

7 responses to “Fixing Duplicate Canonical Link Element in WordPress”

  1. Hi,

    i am Rajesh, developer of Platinum SEO plugin. You don’t have to edit a core file.You can instead add remove_action( ‘wp_head’, ‘rel_canonical’ ); to the functions.php file in your theme.

  2. Hi,

    I upgraded my site and now it has 2 rel=canonicals (same as yours).
    I believe this will affect your site in Google because my site
    went from Google Search page 2 #12 to #18

    I would like to use your option:
    b) comment out the following line in wp-includes/default-filters.php: –
    add_action( ‘wp_head’, ‘rel_canonical’ );

    I’m not a techy person can you give me a step-by-step process
    on how to do this?

    I already found the file and that particular line:
    add_action( ‘wp_head’, ‘rel_canonical’ );
    but I’m not sure what do you mean by “comment out”?


    • Hi Karen, as Rajesh says, it’s actually preferable NOT to edit the core WordPress file as this will get overwritten every time you upgrade WordPress. It’s better to add the following code to your theme’s functions.php file:

      remove_action( ‘wp_head’, ‘rel_canonical’ );

      BTW, to comment out a command in a PHP file put // in front of it

  3. Hi owl,

    I did try this code in the theme’s function:
    // Remove default canonical links
    remove_action(‘wp_head’, ‘rel_canonical’);

    In wp-includes/default-filters.php I added //
    so it looks like this:
    //add_action( ‘wp_head’, ‘rel_canonical’ );

    None of them work…


    • Hi Karen
      The code in my functions.php is identical to yours:

      // remove WP generated canonical as using Platinum SEO pack
      remove_action(‘wp_head’, ‘rel_canonical’);

      so what you are doing should be fine. I just checked your site and there is no duplicate canonical link in the page source….

  4. Hi, I have the same issue. I am using a newspaper theme with a tag div composer plugin and rank math plugin. My home page has two duplicate canonical tags. How can remove one?

Leave a Reply

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