Page 1 of 1

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

Posted: Sat Apr 13, 2019 11:39 am
by andrzej_szpak
Hello.

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

<?php

/**
 * @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";
$this->setGenerator('');

// 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >
<head>
<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
</head>
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?

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

Posted: Sat Apr 13, 2019 6:24 pm
by Per Yngve Berg
Why 2.5.17?
2.5.28 was released in December 2014

https://downloads.joomla.org/cms/joomla ... format=zip