Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question