B
B
bbaggins2017-04-15 11:35:11
Joomla
bbaggins, 2017-04-15 11:35:11

How to add rel="canonical" tag to K2 content on joomla 3?

Friends, hello everyone!
Tell me how to configure the k2 component in Joomla to display canonical?
Found some information here , but not suitable for version 3 of joomla. Sites link or some kind of tip.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bbaggins, 2017-04-15
@bbaggins

Got it, thanks everyone!
// ------------ Start Canonical-Mod
$mainmenu = JFactory::getApplication()->getMenu();
if($mainmenu->getActive()!== $mainmenu->getDefault()) :
$livesite = substr_replace(JURI::root(), '', -1, 1);
$document = JFactory::getDocument();
$docroute = JRoute::_(K2HelperRoute::getItemRoute($this->item->id.':'.$this->item->alias, $this->item->catid.':'.$this ->item->category->alias));
// Start checking system reference in request
$requrl = trim(JFactory::getURI()->toString());
(bool)$valideurl = strpos( $requrl, $docroute );
// If there is no system link in the request
if ($valideurl === false) :
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$livesite.$docroute);
header("Connection: close");
exit();
// If we want to return a 404 error, then comment out 4 lines above this, and uncomment 1 line below.
//JError::raiseError(404, JText::_('PAGE COULD NOT BE FOUND'));
endif;
// End of system link check in request
$document->addHeadLink( $livesite . $docroute, 'canonical', 'rel', '' );
endif;
// ------------ End Canonical-Mod

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question