1

I use this code for the href language in my head.phtml

<?php $website = Mage::app()->getWebsite()->getStores();
foreach ( $website as $store) {
    $lang = $store->getConfig('general/locale/code');
    echo '<link rel="alternate" href="' . $store->getCurrentUrl() . '" hreflang="' . $store->getCode() . '"/>' . "\n";
}?>

Which gives for all my languages the right storeview. Like:

<link rel=alternate href="http://www.mystore.nl/lifestyle.html?___store=nl&amp;___from_store=nl" hreflang=nl />
<link rel=alternate href="http://www.mystore.co.uk/lifestyle.html?___store=en&amp;___from_store=nl" hreflang=en />
etc....

Only for our app we created an extra storeview mobile. But this isn't a language and Google gives error's over this.

How can i excluded the storeview mobile in this code?

1 Answer 1

2

I reckon you can simply replace the following line:

echo '<link rel="alternate" href="' . $store->getCurrentUrl() . '" hreflang="' . $store->getCode() . '"/>' . "\n";

With that one (see the condition before the hreflang attribute):

if("mobile" != $store->getCode()) 
{
    echo '<link rel="alternate" href="' . $store->getCurrentUrl() . '" hreflang="' . $store->getCode() . '"/>' . "\n";
}
5
  • This doens't work. The output is now: <link rel="alternate" href="http://www.mystore.nl/junior.html?___store=nl&amp;___from_store=nl" <?php if("mobile" != $store->getCode()): ?>hreflang="nl"<?php endif; ?>/> It will show the php if as text ...
    – Ronny
    Commented Mar 9, 2016 at 8:56
  • My bad see my edit @Ronny Commented Mar 9, 2016 at 8:59
  • the mobile is still listed '<link rel="alternate" href="mystore.nl/…> <link rel="alternate" href="mystore.co.uk/…> <link rel="alternate" href="mystore.de/…> <link rel="alternate" href="mystore.nl/…>'
    – Ronny
    Commented Mar 9, 2016 at 9:13
  • @Ronny what about now ? Commented Mar 9, 2016 at 9:16
  • That solved it!
    – Ronny
    Commented Mar 9, 2016 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.