HowTo – Canonical Tag for Joomla 1.5 and 2.5 – fast and easy (english version)

The Canonical (Meta) Tag is an in 2009 from Google itself introduced tag to solve duplicate content issues.

The fundamental problem – Duplicate Content

A common example of such a problem is the subsequent activation of „Search Engine Friendly URLs“ in Joomla. As big your joy about the new beautiful links is, as fast you produce duplicate content.
Even your welcome page can be easily represented twice in Google because „“ and „“ are in many cases both true. Also the simultaneous usage of HTTP and HTTPS (SSL) leads to an identical problem.
There are many other reasons why „“ isn’t the only page in the google index and pages like „“ remain there too.

The Canonical tag as savior when it is already too late

If your content is represented several times in the Google index or worse, already linked under different URLs from third parties, the canonical tag can make your day! In these cases the canonical tag indicates where the original source of the content is located. So you can avoid massive redirect work.
Example: Google finds your content e.g. also at „…“ and your canonical tag is set to „“, Google will recognize that the first link isn’t a new content, but only a reference to „/a-great-content“.
In result, the link power isn’t any longer splitted up!

How to set Canonical Tag in Joomla?

Joomla unfortunately has no built-in-function for setting the canonical tag. We have to get the right seo link from the menu items and set it manually.

We coded a small PHP script which uses the Joomla-API to get the seo link from the currently displayed article. To use this code, you just need four simple steps:

  1. Download „“ and unzip „canonical_tag.php“ in your templates directory (e.g. „/htdocs/your-site/templates/beez5/„)
  2. open „index.php“ from your template folder and locate the following line „<jdoc:include type=“head“ />
  3. insert below: „<?php include(„canonical_tag.php“) ?>„. Now, this is what it should look like:
    Canonical Tag - Joomla 1.5
  4. save „index.php“ and reload your website. In your HTML source code you should see the added canonical tag:
    Canonical Tag in Joomla 1.5

That’s it. Check the correct function by entering a non seo link that was previously identified as duplicate content. The canonical tag value should be the seo link for this article.

Important Notes:

  • „Search Engine Friendly URLs“ has to be activated to make this work
  • If your website is available under a HTTP und HTTPS URL, you can set the variable $force_http_base to true. This means that the canonical value always starts with „http://“, whether accessed by http or https.
  • If your content is accessible across multiple domains including sub-domains, there will be set a conanical tag for each domain (very bad!). From a SEO perspective, it should be ensured that your website is only accessible by a single domain! This could be done by a appropriate redirection on the web server or via „.htaccess“ file. Please remember that even and are two different domains which should be redirected to a single domain!
  • The code runs with Joomla 1.5.x and 2.5.x
  • If „article id“ isn’t provided because of an joomla extension (e.g. a contact form extension), the canonical tag won’t be set.

To report a bug, please mail to:


>> Anleitung – Canonical Tag in Joomla richtig setzen – German Version

24 Gedanken zu “HowTo – Canonical Tag for Joomla 1.5 and 2.5 – fast and easy (english version)

  1. Pingback: Canonical Tag für Joomla 1.5.x und 2.5.x – Beheben von Duplicate Content schnell und einfach – Anleitung | Concept-BR Blog

  2. Great script for Joomla 2.5, easily solve duplicate pages problem. Also superb support for making custom adjustments. Best free canonical tag extension so far!

    Good luck with the work!

  3. Great Script!
    However, it has a Bug: „id“ is not solely used for articles, but also for category links, so your script will use wrong URLs on Category link (i.e. index.php?option=com_content&view=category&layout=blog&id=8 will pull the URL from Article id 8, instead of the correct Category View).

    I fixed it by adding
    $view = JRequest::getVar(‚view‘);
    on line 45 (after $article_id = …)


    if($clean_uri != „“ && $article_id > 0 && $view == ‚article‘)
    // get current menu url for canonical meta tag creation
    // ====================================================

    // get url for article
    $link = JRoute::_(ContentHelperRoute::getArticleRoute($article_id, 0));

    // set value
    $canonical_value = $base_url.$link;
    else if($clean_uri != „“ && $article_id > 0 && $view == ‚category‘)
    // get current menu url for canonical meta tag creation
    // ====================================================

    // get url for category
    $link = JRoute::_(ContentHelperRoute::getCategoryRoute($article_id, 0));

    // set value
    $canonical_value = $base_url.$link;
    else if($clean_uri == „“)

    best regards

    • Hi Alberto,

      K2 is an extension so the script couldn’t set the canonical tag. We wan’t to support also a couple of extension in future, but this is a low priority goal. Sorry…..

      Best Regards

        • For static html pages you can’t use our piece of code. It is only for Joomla CMS. For static html pages: insert the meta canonical tag for each site or let – for example – parse your php engine also html files, so you can use php includes in html files to reduce redundancy.

  4. Hello,
    I followed your instructions but I found this errors:
    Warning: include(�canonical_tagphp�) [function.include]: failed to open stream: No such file or directory in /home/xxxxxx/public_html/templates/yyyyyy/index.php on line 32

    Warning: include() [function.include]: Failed opening ‚�canonical_tagphp�‘ for inclusion (include_path=‘.:/usr/lib/php:/usr/local/lib/php‘) in /home/xxxxxx/public_html/templates/yyyyyy/index.php on line 32

  5. I have followed your instruction for my joomla used Warp framework and nothing happens. There is not any rel tag exist when I check in html code. Could you please help me out of it?

    • Hi Ken,
      did you check the correct position of the php include snippet in your warp framework? Did you test it with an „normal“ article page?
      Best Regards

  6. Hi,
    I really liked it but i found a bug.
    If I open this url – then canonical tag works fine. And again if I open url as then it works fine here too. But if I open the url as then this does not work. This shows the canonical tag but different value.
    Here this you need to fix.

    • Hi,

      which joomla version did you use? Looks like a 1.5 URL? Please download the script and replace it with your existing one. I made some changes these days. In Joomla 2.5 your case works correctly.

      Best Regards

      • Hi,
        Yes this issue is happening with Joomla 1.5.
        I downloaded and uploaded again. The same issue still exist. Can you please fix this for J1.5 package?

  7. Hi,

    thanks for script first of all. I am having a problem, though. Some of my pages have set their canoncial URLs with „www“ and some don’t. I would like all of them to have „www“. Do you have any idea what I did wrong?

    Thank you!

    • Hi,

      this is a problem you should solve by using the htaccess file and a generic redirect for all „non-www“ stuff to „www“. This should do:

      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^www\.
      RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

  8. Thanks for the great post. I am having some trouble making this work as it is returning the following errors in the browser:

    Warning: include(“canonical_tagphp”) [function.include]: failed to open stream: No such file or directory in /home/content/68/9368268/html/spearmagazine/templates/newafrican/index.php on line 8

    Warning: include() [function.include]: Failed opening ‚“canonical_tagphp”‘ for inclusion (include_path=‘.:/usr/local/php5_3/lib/php‘) in /home/content/68/9368268/html/spearmagazine/templates/newafrican/index.php on line 8

    Any help would be greatly received

    • Hi,

      also for any other who have problems with the php include: please try an absolute path to the file. For any reason, the given relative path can result in an error.

      For the example above try:
      include(“ /home/content/68/9368268/html/spearmagazine/templates/newafrican/canonical_tag.php”)

      Best Regards

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.