Magento changing the language selector

Magento changing the language selector

July 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento changing the language selector

Changing Magento Language Selector to Separate Links

In Magento, by default, you can switch between languages using a dropdown selector. This selector is defined in app/design/frontend/base/default/template/page/switch/language.phtml. Here’s the default code:

<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <label for="select-language"><?php echo $this->__('Your Language:') ?></label>
    <select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
        <?php foreach ($this->getStores() as $_lang): ?>
            <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
            <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php      echo $this->htmlEscape($_lang->getName()) ?></option>
        <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

This code creates a select box with options for all available languages. If you want to change this to display separate links instead, follow these steps:

You can replace the select box with anchor tags (<a>) in your custom template file app/design/frontend/default/projectname/template/page/switch/language.phtml. Here’s an example:

<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <?php foreach ($this->getStores() as $_lang):?>
        <a href="<?php echo Mage::getUrl() . '?___store=' . $_lang->getId(); ?>" title=""><?php echo $this->htmlEscape($_lang->getName()); ?></a>
    <?php endforeach; ?>
</div>
<?php endif; ?>

In this code, we’re looping through the available stores and creating an anchor tag for each one. The href attribute uses Mage::getUrl() to generate the URL and appends the store ID as a parameter.

Fixing the Redirect Issue

You mentioned that switching languages redirects you to the homepage instead of keeping you on the current page. This happens because Magento needs to know which URL to redirect to when the language changes.

To fix this, you should use getCurrentUrl() instead of Mage::getUrl(). The updated code looks like this:

<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <?php foreach ($this->getStores() as $_lang):?>
        <a href="<?php echo $_lang->getCurrentUrl(); ?>?___store=<?php echo $_lang->getId(); ?>" title=""><?php echo $this->htmlEscape($_lang->getName()); ?></a>
    <?php endforeach; ?>
</div>
<?php endif; ?>

In this version, getCurrentUrl() is used to generate the URL for each language. This ensures that when you click a link, Magento redirects you to the correct page in the selected language.

Conclusion

Changing the Magento language selector from a dropdown to separate links involves modifying the language.phtml file in your theme directory. By replacing the select box with anchor tags and using getCurrentUrl() for the URLs, you can create a cleaner layout that displays each language as a separate link.

Remember that theme files are overwritten during an upgrade, so it’s best to make these changes in a custom theme or use a child theme to preserve your modifications. For more information on working with themes and templates in Magento, consider checking out our guide at https://laravelcompany.com/magento-themes-templates.

Happy coding! Let me know if you have any other questions.

Themes

Our network