Avoid Duplicate Content – Use Canonical URL in WordPress

WordPress Logo

The new talk of the SEO world is ‘Canonical URL‘. What is canonical URL? This is the definition given in Google’s Webmaster Central Blog…

a format that allows you to publicly specify your preferred version of a URL. If your site has identical or vastly similar content that’s accessible through multiple URLs, this format provides you with more control over the URL returned in search results. It also helps to make sure that properties such as link popularity are consolidated to your preferred version.

Emphasis mine

It is very easy to specify the canonical URL of a page – all you have to do is add this line in the head section

<link rel="canonical" href="http://binnyva.com/" />

The purpose of this tag is to prevent the problem of duplicate content.

The best thing about this tag is that all three major search engines(Google, Yahoo and MS Live) support this initiative.


If you are on wordpress, this tag can be integrated into your theme easily. There is a plugin to do the job for you – but you don’t need a plugin to do something as simple as this.


Go to the theme folder in wordpress(wp-content/themes/<theme_name>) and open the file header.php in your favorite editor. Now find the line


and add the following code before that line…

<?php if ( is_singular() ) { ?>
<link rel="canonical" href="<?php the_permalink(); ?>" /> 
<?php } ?>

Now, it should look something like this…

<?php if ( is_singular() ) { ?>
<link rel="canonical" href="<?php the_permalink(); ?>" /> 
<?php } ?>

That’s it – you are done! Save the file and upload it to your server.

This fix will add the canonical URL tag to all the posts and pages of your blog. If you want to see a blog that have implemented this fix, take a look at the source of this page.

Related Links


  1. i think your understanding of where to place the canonical URL is wrong. You need to place them on the duplicate pages and not on the single posts. Read over google’s blog post again.

  2. @Rajesh
    It will be placed on the duplicate URLs as well – for eg, this page is a duplicate of the current page. The canonical URL link will point to the right URL in that page.

    This fix also places the canonical link in the correct page as well – this is valid. The official example page – Star wars wikia does this too.

  3. Yes, it should be placed on the duplicates but i am not sure about whether it is ok to place it on the original as well… but as you say, the example does it on both…

  4. I tried to take a look at Gizmodo.com ( a giant tech blog) and I can see they are placing the canonical URL link everywhere, even in their search page and tag archives. Anyone have any idea? If the big blog boy can do so, I guess we the small guy can follow too…

  5. watched Matt for 20 minutes on this stuff πŸ™‚ now I understand how important it is πŸ˜‰ need to give it a try .. I think I will use the plugin, since I usually change the theme a lot

  6. A canonical tag is given to the duplicate pages to say the search engine that the original source point to the location given in the link tag. It doesn’t make sense to me adding to all the pages unless it is duplicate. You can hard code this to the pages, better use a plugin for wp. I have written a post on this

  7. Nice. One problem for me though, it does not seem to place the rel=”canonical” link to the home page. Any work-around or is this not a concern?

  8. I like the idea of all of this, and I have no problem copying and pasting the code you provide. If I do a WordPress Upgrade or a Theme version upgrade, will I have to recode this?


  9. Really dumb question, sorry. I decided to stop using plugins for WordPress and do the SEO implementations as best I can myself with php, etc.

    If I use THIS canonical url fix, will this cause issues with the canonical url’s that WordPress already has built in??

    I know that all-in-one-seo plugin overrides WordPresses canonical url fix and then they use their own, correct? So, would I have to disable WordPress’s in the head and then use this head?

  10. I didn’t tried this solution because I didn’t know about the canonical metatag. Interesting concept, hope to work. I had this problem with Avarcade script, Google indexed 2 pages with the same content for every page, seo friendly version and the non-seo friendly version.

  11. Why is some people worried about having the canonical url on the single page?

    If it’s on the single page it’s pointing to itself, so it’s all good. πŸ˜‰

  12. Hi,

    You said that the code you mention will “add the canonical URL tag to all the posts and pages of your blog”.

    What if i want to make any single post of my choice to insert “canonical”. How can i do that?


3 Trackbacks / Pingbacks

  1. WordPress Plugin Killer: The Series | Bin-Blog
  2. Canonical Links in Wordpress, and Some SEO lessons | Blog of Small Things
  3. Adding Social Bookmarking Link in WordPress - Without Plugins : Boykma.Pro - English

Comments are closed.