Guides & Tutorials

Technology tutorials, technology guides and more

Canonical tags were introduced by all the major search engines in 2009. It was fairly unprecedented to have Google, Yahoo, and Microsoft unite to offer a solution to a problem. The canonical tag solves duplicate content indexation. If you are running Joomla CMS you have duplicate content. A Canonical tag is an HTML attribute that identifies a URL as being canonical to the page it is served on. The canonical tag looks like rel="canonical".

A few of the problems caused by duplicate content.

  • Search engines don’t know which version to index/not-index
  • Search engines don’t know which version to show in the results
  • Users will visit all variants causing poor analytics data
  • Users will link to all variants causing poor link equity on each variant since it is spread across all variants

The canonical tag is a great way to fix the duplicate content issue for search engines and it is placed on all possible variants and tells search engines which one the primary URL is.

Adding canonical tags using custom fields in Joomla

In the administrative backend: Admin Menu > Content > Field Groups and Fields

1. Create a Field Group

  • Title – SEO
  • Description – Custom SEO fields

2. Create a new Field

  • Title – Canonical URL
  • Type – URL (url)
  • Name – Leave Blank
  • Label – Leave Blank
  • Description – Canonical tag to be placed in the HTML head
  • Required – No
  • Default Value – Leave Blank
  • Schemes – HTTP, HTTPS
  • Relative – No
  • Status – Published
  • Field Group – SEO
  • Category – All
  • Access – Public
  • Language – All
  • Placeholder –
  • Render Class – Leave Blank
  • Edit Class – Leave Blank
  • Show Label – Show
  • Show On – Both
  • Automatic Display – Do not automatically display

3. Create a view override and add code to the template default.php

Copy /components/com_content/views/article/tmpl/default.php to /templates/YOUR_TEMPLATE/html/com_content/article/

Edit /templates/YOUR_TEMPLATE/html/com_content/article/default.php and insert around line 26. Where X is the ID number of your new Canonical URL field created.

foreach ($this->item->jcfields as $field) {
  if ($field->id === 'X') {
    // If field not empty
    if (!empty($field->rawvalue)) {
      // Insert content with markup into the HTML head
      $canUrl = '';
      $document = JFactory::getDocument();