How to Remove ?___store= from Hreflang URL

hreflang

<?php foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            $storeCode = $store->getCode();
            echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $store->getCurrentUrl(false) . '"/>' . "\n";
        }
    } } ?>

This produces, for example,

<link rel="alternate" hreflang="en_ca" href="http://mywebsite.com/en/?___store=en_ca">

But I want to remove ?___store=en_ca part.

I tried replacing:

$this->_href = $this->_href . $symbol . "___store=" . $store->getCode();

into:

$this->_href = $this->_href;

in app/code/core/Mage/Catalog/Block/Widget/Link.php

But didn't work.

How can I achieve this?

Best Answer

Why not keep it simple.

Instead of making new module etc just remove last part of your string containing ?___store=en_ca

<?php foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {

            // check if $url contain ?, if yes then strip last part of url
            $url = $store->getCurrentUrl(false); 
            if((strpos($url, '?') !== false)){ 
                $url = substr($url, 0, strrpos($url, "?"));
            }

            $storeCode = $store->getCode(); // addad url as variable
            echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $url . '"/>' . "\n";
        }
    } } ?>
Related Topic