I am adding hreflang-tags to a multi-language Magento store. I found the code below on here and used it in the page header. It does what it's supposed to, but I'm looking for another solution.
<?php
$website = Mage::app()->getWebsite()->getStores();
foreach ( $website as $store) {
$lang = $store->getConfig('general/locale/code');
if (strtolower($lang) == 'en_us'){
$lang = 'en-us'; // en-us or other
}
if (strtolower($lang) == 'nl_nl'){
$lang = 'nl-nl'; // nl-nl or other
}
echo '<link rel="alternate" href="' . $store->getCurrentUrl() . '" hreflang="' . $lang . '"/>' . "\n";
}
?>
This returns a tag like:
<link rel="alternate" href="https://example.com/category?___store=english&___from_store=english" hreflang="en-us"/>
But I would rather have a code that returns a tag with the actual URL as specified in the backend.
For example:
A product named "shoulder-bag" in category "bags"
returns an URL in English as: example.com/bags/shoulder-bag
And in Dutch as: example.com/tassen/schouder-tas
I'm also missing the code to specify a "default"
Can anybody help me out? Thanks!