Bin-Blog logoBin-Blog

Learn about the latest in Web Development – as soon as I do.

Avoid Duplicate Content – Use Canonical URL in WordPress

By • Feb 16th, 2009 • Category: Blogging, Google, SEO, Web Development, 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.

WordPress

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.

header.php

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

</head>

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 } ?>
</head>

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


24 Responses »

  1. Rajesh says:

    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. Binny V A says:

    @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. Rajesh says:

    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. dinu says:

    hmm , thanks for the info .. I actually need to learn this .. I am really bad with SEO :D

  5. Ken says:

    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…

  6. [...] « Avoid Duplicate Content – Use Canonical URL in WordPress [...]

  7. dinu says:

    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

  8. [...] was learning about Canonical Links, and how it works on WordPress. The following video and Binny’s post about the plugin and code for canonical links in WordPress helped. I used the plugin instead of [...]

  9. You are right, we don’t need a plugin to do something as simple as this.

  10. [...] Avoid Duplicate Content – Use Canonical URL in WordPress [...]

  11. SEO Herald says:

    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

  12. Great Blog. I am working for SEO campaign of my site and found this blog which is quite a informative….thanks guys

  13. iceflatline says:

    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?

  14. TedV says:

    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?

    Thanks!

  15. it solved my problem on my wordpress blog, when severel NewsFeeds (NyhedsLinks) provide the same story/permalink… thanks !

  16. *it DOES NOT solve my problem with my blog and newsfeeds, i meant..sorry for english

  17. Rob says:

    Hi,

    Excellent post, right to the point. I linked your post from my blog: http://www.web-design-talk.co.uk/164/prevent-duplicate-content-using-the-canonical-url-tag/

    Also, it’s worth noting you could use the all in one seo plugin for wordpress, as that generates canocial tags for all your posts.

    Thanks

  18. James says:

    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?

  19. Juegos says:

    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.

  20. Jim says:

    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. ;)

  21. Ayush Gupta says:

    I think this is not working now. I tried this with my blog but seems its not working properly. Please check from your side.

  22. gamemunition says:

    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?

    Thanks.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>