I have multiple store site in magento. i wanted to add hreflang for my stores and thanks to one of the post here i have managed to do so.
the code i wrote in my
app / design / frontend / mytheme / default / template / page / html / head.phtml
and the code it self is
$website = Mage::app()->getWebsite()->getStores();
foreach ( $website as $store) {
$lang = $store->getConfig('general/locale/code');
echo '<link rel="alternate" href="' . preg_replace('/\?.*/', '', $store->getCurrentUrl()) . '" hreflang="' . $lang . '"/>' . "\n";
}
and the result i am getting on front end is
<link rel="alternate" href="http://www.mysite.co.uk/en/" hreflang="en_GB"/>
<link rel="alternate" href="http://www.mysite.co.uk/fr/" hreflang="fr_FR"/>
<link rel="alternate" href="http://www.mysite.co.uk/de/" hreflang="de_DE"/>
<link rel="alternate" href="http://www.mysite.co.uk/it/" hreflang="it_IT"/>
but the issue is, as you know hreflang="en_GB" is incorrect and google wont recognize it. the tag should be hreflang="en-gb" dash - instead of _ and all lower caps. how to achieve this? and 2nd is it important to have URL parameter /en/ for English site? cant this be without /en/? if so then how to achieve this? rest EU sites are fine to have parameters but English store should be with out it. Thanks