Joomla 2.5.17 adds meta tag (canonical) from other view than current when cache is on

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Jun 02, 2012 10:50 pm

Joomla 2.5.17 adds meta tag (canonical) from other view than current when cache is on

Post by andrzej_szpak » Sat Apr 13, 2019 11:39 am


I am using Joomla! 2.5.17 Stable version of Joomla. I have created a component that uses a code to add canonical URL:

Code: Select all

$document = JFactory::getDocument();
$document->addCustomTag("some custom code");
$document->addCustomTag("<link rel=\"canonical\" href=\"$theCorrectCanonical\" />");
it is located in components/my-component/views/my-view/tmpl/default.php

Since i have a lots of views it is defined in each view for my-view, my-view2 etc.

It was working fine. The canonical link was added properly. Event if i had cache on.
And lately i have disabled modules i didn't need anymore. So i disabled them and website was working fine after this.
Suddenly i have discovered Google marks my pages as non-canonical.
After looking at the code of website i have noticed that the HTML head looks like this:

Code: Select all

some custom code
<link rel="canonical" href="correct-url" />
<link rel="canonical" href="url-of-a-page-i-visited-second-ago" />
So it looks like, that for whatever crazy reason Joomla ads not only the correct canonical but also a canonical tag of other subpage i have visited second ago. Making Google believe it is a non-canonical of a other page.

I have tried to search for a solution, but didn't find any. Also i have noticed that when i disable cache in config with:

Code: Select all

	public $caching = '0';
And in Addons -> System cache (i disable it). It goes back to normal. It does not add the second meta tag of canonical.

Index.php of my template looks like this:

Code: Select all


 * @version                $Id: index.php 21518 2011-06-10 21:38:12Z chdemko $
 * @package                Joomla.Site
 * @subpackage  Templates.beez_20
 * @copyright        Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license                GNU General Public License version 2 or later; see LICENSE.txt

$resourcesVersion = "1.1";

// No direct access.
defined('_JEXEC') or die;

// check modules
$showRightColumn        = ($this->countModules('position-3') or $this->countModules('position-6') or $this->countModules('position-8'));
$showbottom                        = ($this->countModules('position-9') or $this->countModules('position-10') or $this->countModules('position-11'));
$showleft                        = ($this->countModules('position-4') or $this->countModules('position-7') or $this->countModules('position-5'));

if ($showRightColumn==0 and $showleft==0) {
        $showno = 0;

JHtml::_('behavior.framework', true);

// get params
$color              = $this->params->get('templatecolor');
$logo               = $this->params->get('logo');
$navposition        = $this->params->get('navposition');
$app                = JFactory::getApplication();
$doc        = JFactory::getDocument();
$templateparams     = $app->getTemplate(true)->params;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >
<jdoc:include type="head" />
<meta name="viewport" content="width=device-width, initial-scale=1" />          
some stylesheets embedded directly
some scripts embedded directly
a meta tag embedded directly
I run out of ideas why it behaves this way. I don't know from where the second canonical comes from. It is not set in the view currently displayed. Such canonical is only set by other view in the same component. But how this lands into other view code? And only with cache = on?

Do you have any clues i could follow to find what is the issue here?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 27414
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Joomla 2.5.17 adds meta tag (canonical) from other view than current when cache is on

Post by Per Yngve Berg » Sat Apr 13, 2019 6:24 pm

Why 2.5.17?
2.5.28 was released in December 2014 ... format=zip


Return to “General Questions/New to Joomla! 2.5”