hreflang seo optimize

20.12.2017 17:59
#1
le5
Joomshopping forum user no avatar
Name: le5 GmbH
17.03.2012
Posts: 74
Quote
hreflang seo optimize

Hello

I tried to implement the <link hreflang="" href=""> tag on the detail product template.

But I failed. I tried following.

Since I'm not aware, which other internal functions exits from joomshopping, this code maybe anyway not very nice...
And be carefully, since my default menu item in each language is the shop categories view it works with the itemid. If the shop is not the default menu item, this code anyway fails for getting the itemid.


$document = JFactory::getDocument();
$app = JFactory::getApplication();
$menu = $app->getMenu();
$languages = JLanguageHelper::getLanguages();
$lang = JFactory::getLanguage();
$currentLanguage = $lang->getTag();

foreach ($languages as $item)
{
$default = $menu->getDefault($item->lang_code);

if($item->lang_code != $currentLanguage) {
$hreflang = 'index.php?option=com_jshopping&controller=product&task=view&category_id=' . $this->category_id;
$hreflang .= '&product_id=' . $this->product->product_id . '&Itemid=' . $default->id . '&lang=' . substr($default->language, 0, 2);
$document->addCustomTag('<link rel="alternate" hreflang="' . $default->language . '" href="' . JRoot::_($hreflang) . '">');
}
}


This only works on SEF switched off. If I use SEF on, the language slugs are used of the current viewed language and not the ones of the "lang" param.

It is sure possible, that I totaly miss something here. But It looks like, the route function does not allow me, to create routes to other languages.

Any ideas or help are welcome.
Pawel

 


Copyrights MAXXmarketing GmbH. Alle Rechte vorbehalten
Durch die Nutzung dieser Website stimme ich zu, dass Cookies zur optimalen Gestaltung der Website sowie zur Analyse der Nutzung der Website verwendet werden. Weiterführende Informationen finden Sie hier. OK, einverstanden.