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 „www.your-domain.com“ and „www.your-domain.com/index.html“ 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 „www.your-domain.com/a-great-content“ isn’t the only page in the google index and pages like „http://www.your-domain.com/index.php?option=com_content&view=article&id=2&Itemid=102“ 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 „http://www.your-domain.com/index.php?option=com_content&vie…“ and your canonical tag is set to „www.your-domain.com/a-great-content“, 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:
- Download „canonical-tag.zip“ and unzip „canonical_tag.php“ in your templates directory (e.g. „/htdocs/your-site/templates/beez5/„)
- open „index.php“ from your template folder and locate the following line „<jdoc:include type=“head“ />„
- insert below: „<?php include(„canonical_tag.php“) ?>„. Now, this is what it should look like:
- save „index.php“ and reload your website. In your HTML source code you should see the added canonical tag:
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.
- „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 www.your-domain.com and your-domain.com 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: firstname.lastname@example.org.