I have three websites under single magento installation and would like to generate hreflang tags for each websites manually.
I used the code mentioned in this question
<?php foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
$storeCode = substr(Mage::getStoreConfig('general/locale/code', $store->getId()),0,2);
echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $store->getCurrentUrl(false) . '"/>' . "\n";
}
}
}
?>
However, this only outputs hreflang available as storeview language. Also no coutntry is specified. I would like to use more hreflang tags as fi,de, en-ca etc.
How can I manually write hreflang tag?
--- UPDATE ---
For now, I could manually write hreflang by creating head.phtml for each websites. Then to add, for example,
<link rel="alternate" href="http://www.mywebsite.com<?php $urlString = Mage::helper('core/url')->getCurrentUrl(); $url = Mage::getSingleton('core/url')->parseUrl($urlString); $path = $url->getPath();echo $path ?>" hreflang="en-gb" />
This works. And so far Google Webmastertool is not giving any errors. However, this method obviously doesn't list all the available languages in my shop. But if I don't create each head.phtml and just have one head.phtml with the code above, it will add extra store code when you are on different website. Any good solution for this?