Canonical tag for SEO


Google, Yahoo and Microsoft are now supporting the canonical meta tag as the standard for identifying the actual source of your content: the real URL that you want to recieve page rank for your key terms.

Many sites have the same content show up with different URLs due to search features, dynamically generated URLS, tags, etc. Google, Yahoo and other search engines have been knocking your sites for having duplicate content as if you were spamming your terms. In other words, having multiple URLs pointing to the same content has been hurting your page rank and your site.

Now you have a way to make sure that your multiple content helps you instead of hurts you.

Implementing the CANONICAL meta tag

  1. Pick one URL for your page – “the pretty, preferred or canonical URL” (to quote Matt Cutts). For example, this page’s main, or canonical, URL is http://www.evotech.net/blog/2009/02/canonical-tag-for-seo/, though you may find it thru http://www.evotech.net/blog/?p=69 or http://www.evotech.net/blog/?s=SEO, http://www.evotech.net/blog/category/seo/ or simply http://www.evotech.net/blog.
  2. Figure out how to include your page’s main URL in pages that are dynamically generated. For example, I need to figure out how to include my primary URL – http://www.evotech.net/blog/2009/02/canonical-tag-for-seo/- in the web page showing this content no matter which URL from the bullet point above is shown.
  3. Once you know how to get the URL you picked in step 1 into your possible other pages feeding the content from your main URL, place the canonical link tag inside the tag with the main content’s URL. For this example, I would place: <link rel=”canonical” href=”http://www.evotech.net/blog/2009/02/canonical-tag-for-seo/” /> in my header.

The syntax is similar to the stylesheet link tag:

<link rel=”canonical” href=”http://www.yourdomain.com/yourpage” />

The canonical tag is ONLY for webpages in the same domain. So, http://evotech.net/blog pointing to http://blog.evotech.net or http://www.evotech.net/blog is fine. However, I can’t point http://estelleweyl.com/blog to http://evotech.net/blog if I were to have that URL as an addon domain on this server.

Now I just have to figure out how to do step 2 so I can create canonical links for this blog.

Added Notes:

Lori basically figured it out for us: (copied from http://beedragon.com/wp-test-site/2009/02/13/add-canonical-link/). Thanks!

Add canonical link tag to head

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

Occurs to me now that you’d have to hardcode main url, then get the slug and other url info dynamically:

<?php if ( is_single() || is_page() ) { ?>
<link rel="canonical" href="http://mainurl.com/<?php echo the_time('Y'); ?>/<?php echo the_time('m'); ?>/<?php echo the_time('d'); ?>/<?php echo $post->post_name; ?>" />
<?php } ?>

There is probably a prettier and/or more efficient way to do that, but can’t think of one at the moment.


This entry was posted in Best Practices, SEO, Web Development. Bookmark the permalink.

7 Responses to Canonical tag for SEO

  1. Lori says:

    That’s very cool. Thanks for the info. Maybe I will finally change my url/site name 🙂

    How about this in the “ for the blog links?

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

    Only had time for a quick test, but it seemed to do the trick.

  2. Lori says:

    oops. tags were stripped. Will try again…

    How about this in the head for the blog links?

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

  3. Florian says:

    Very interesting, although I think some people with affiliate URLs ranking in the SERPs won’t be happy about the possible loss.

  4. Diamara says:

    Nice explanation some examples of why this is important and a link to a Firefox extension to help developers can be found here: http://digitaliconoclasm.blogspot.com/2009/02/i-say-tomato-you-say-tomatosortname.html

  5. Trey Brister says:

    Hi, since canonical domain names will not work cross domain, here is a good solution for ASP users.

    http://www.easttexasautos.com/autoblog/?p=3

    PS: I linked to this URL in the post. Can I get a reciprocal link?

  6. I was able to use the canonical tag to fix a tricky problem where Google wasn’t honoring the 301 redirect I had in place directing search engine spiders from the http://mysite.com version of my site to the http://www.mysite.com version. It was still indexing my main page without the www while it indexed inner pages just fine with the www. My host recommended trying the canonical tag because we were pretty much out of other solutions.