How to add Google’s canonical tag to Joomla articles

Background:

I used to use non-SEF url’s on a Joomla site, and recently turned on Joomla’s built-in SEF. Problem is that the old URL’s still “work”. Of course, this is great for people who visit – not so great when GoogleBot comes along.

GoogleBot comes happily along and for any given article sees the original archaic url with a bunch of parameters that have been there forever. Of course, there’s little incentive for it to use the “cleaner” versions. As far as it’s concerned, the archaic stuff is the original, and the new url’s are duplicate content. It could eventually change it’s mind as to the “preferred” page on it’s own, but there are a few fighting factors here. On one hand, the sitemap points to the “new” one, and it’s predominantly linked to through the current site. On the other hand, anyone who’s linked to the site in the past has linked to the “old” one, and let’s face it – it was there first.

To make the change and get Google looking at the right page, we’ll go over the things I tried that didn’t work, and then the thing I tried that did work:

Stuff that didn’t work:

What did work:

You can find it in the Joomla Extensions Directory, or right from the developer’s site (Web Archive). The site is mainly french, but there’s enough english to get you by – the instructions after you install it are dead-easy.

Install it, enable the plugin, and then it’s simply a matter of throwing {tag}whatever-you-want-in-the-head{/tag} in each of your content pages. So for a canonical entry, something like this:

{tag}<link rel=”canonical” href=”//www.website.com/current-friendly-url.html”/>{/tag}

You can stick it anywhere in the content. The downside is that you obviously have to do this for each content page, meaning you’ll have to know the “desired” url. On the plus side, it’s easy to do (especially compared to the above options), it gives you full control for each page, you can stick other stuff in the “head” section if you want it later, and it’s free.

10 Comments | Leave a Comment

 Sort by Oldest | Sort by Newest
  1. Markus on November 13, 2009 - click here to reply

    Hi Matt!
    Thanks for this blog, it sent me on the track to find a solution to implement a canonical tag in Joomla. I found one more solution that worked for my needs I wanted to share it here with you and others who might find it useful.

    My problem was I had url:s like mysite.com/page1.htm?var1=one and wanted a canonical tag saying mysite.com/page1.htm that was automatically generated for each page.

    In my template file right after:
    <?php
    defined('_JEXEC') or die('Restricted access');

    I added:
    $canonical = JURI::current();

    And then further down in the template just before the tag, I added:
    <link rel="canonical" href="”>

    Worked like a charm for me. Not sure if it will work in all other cases but give it a try.

    All the best,
    Markus

  2. Philip on March 24, 2010 - click here to reply

    Thanks for this plugin. I’ve been searching high and low for a way to add canonical tags to article pages. You are a life saver!

  3. Expert SEO India on October 20, 2010 - click here to reply

    Thanks for such a wonderful information, iwas looking for the extension which can install a canonical into my website. My site creating a string after the URLs so i need the plug in. Thanks Again.

  4. Bruno on March 8, 2011 - click here to reply

    Thank you Matt!!! Great solution!

  5. Loz on August 23, 2011 - click here to reply

    Matt thank you so much, was just what i needed and also thank you for talking it out in such an easy to follow way..Thank you

  6. Jürgen on January 10, 2013 - click here to reply

    Hi,
    i also had trouble with setting the canonical tag in my joomla pages. I found a simple and quick solution, writing a small script. The script uses the article id to get the seo url an set it to the canonical tag. I also used “$canonical = JURI::current();” and solution like that but if there is a “dirty” link like “/index.php?option=com_content&view=article&id=1&Itemid=109” it will be also set instead of the seo url.

    My script can be easily included in every template from joomla 1.5 to 2.5. The download link and a tutorial can be found here: http://www.concept-br.de/blog/canonical-tag-for-joomla/#more-136

    Hope this helps somebody!

    Best regards, J.

  7. choz on March 16, 2013 - click here to reply

    thank youuuu
    just a bit correction, from what i saw in jostag documentation, there should be no included..
    eg. when your gave examples like
    {tag}{/tag} , it would be better to write it down like this
    {tag}link rel=”canonical” href=”http://www.website.com/current-friendly-url.html”{/tag}

  8. Klement on May 23, 2013 - click here to reply

    You Sir, deserve a medal.

    I have been struggling with this for more than 8 hours straight. I was just about to give up on this.

    THANK YOU!

  9. I write a joomla plugin for solving articles duplicate problem. this plugin canonical all article addresses to correct and main address. you can download here:
    http://extensions.joomla.org/extensions/extension/site-management/seo-a-metadata/articles-canonical

  10. Arash on August 6, 2017 - click here to reply

    thank you sir

Leave a Comment

You can use an alias and fake email. However, if you choose to use a real email, "gravatars" are supported. You can check the privacy policy for more details.