#1255 Posted in ‘Route 66’

Latest post by Lefteris Kavadas on Monday, 07 October 2024 12:59 EEST

Michael Richey
Extensions that create their own canonical tags are ignored by route66 plugin.
several lines of code added to the system/route66 plugin fix the issue.
From the comment, I added 8 lines.  Then I added one test to the addHeadLink test (&&empty($canonical))What this modification does is check the head links for an existing canonical tag.  If it's empty - your route66 generated canonical tag is added.
public function onBeforeCompileHead()
{
$application = JFactory::getApplication();
$document = JFactory::getDocument();

if ($application->isClient('site') && $document->getType() == 'html')
{
// Check if a canonical html tag already exists (for instance, added by a component).
$canonical = '';

foreach ($document->_links as $linkUrl => $link) {
if (isset($link['relation']) && $link['relation'] === 'canonical') {
$canonical = $linkUrl;
break;
}
}

if ($this->params->get('canonical', 1) && $this->canonical && empty($canonical))
{
$document->addHeadLink(htmlspecialchars($this->canonical), 'canonical');
}

if ($this->params->get('facebookPageId'))
{
$document->addCustomTag('<meta property="fb:pages" content="' . $this->params->get('facebookPageId') . '" />');
}

if (JPluginHelper::isEnabled('content', 'route66metadata'))
{
$this->setMetadata();
}
}
}

Lefteris Kavadas

Hi Michael,

Thank you for the code you have provided. However, note that Route 66 has an option for disabling canonical links. You can use that option if you are using a different extension for that.

Regards

Michael Richey
No, I'm not using another extension to generate canonical links - one of the extensions I use (a component) generates its own canonical links for pages generated by that extension.  It's not sitewide, just one menu item does this.
The Joomla SEF plugin can also generate canonical links if it detects that one is not already present.  I adapted the Joomla SEF plugin code to your extension, so yours does not generate canonical links when something else has already done it.

Lefteris Kavadas

Hi Michael,

I will review the code. Until then can you try to use the exclusions option in Route 66 options? Just select your component there and Route 66 will not generate canonical links for it.

Please let me know if that works for you.

 

Regards

Note: An active subscription is required in order to get support for our paid extensions. For our free extensions, if you don't have an account, register and then submit your support request.  In case you just want to ask a question, you can also use the contact form .

Firecoders
Are you using our extensions? Please post a review at the Joomla extensions directory!
Post a review