Back to blog
Hreflang Validator9 min readSeptember 3, 2026

How to Implement Hreflang in Magento 2: Store Views, Extensions and XML

Magento 2 does not generate hreflang natively. How to implement it with an extension or your own layout XML, and how to avoid store code URL errors and catalogue gaps between store views.


Start with the part that surprises people: Magento 2 does not add hreflang tags on its own. It models languages and countries in remarkable detail through store views, but it does not turn that structure into signals for Google. If you have installed nothing and touched no layout, your multilingual store has no hreflang.

How multilingual works in Magento 2

The hierarchy is website → store → store view, and the store view is what matters here: each one has its own locale, its own visible catalogue and its own URL. An hreflang group in Magento is, in practice, the set of store views representing the same page in different languages or countries.

  1. 1.Under Stores → All Stores, check which store views you have and which website they belong to.
  2. 2.Under Stores → Configuration → General → Locale Options, review each store view’s locale. The hreflang code comes from there, so a wrong locale propagates everywhere.
  3. 3.Under Stores → Configuration → General → Web, decide how each store view is served: by store code in the URL, by subdomain, or by its own domain.

If "Add Store Code to URLs" is enabled, your URLs look like example.com/en/... with the store view code. That is valid, but make sure hreflang declares exactly that URL and not the version without the code: both usually respond, and pointing at the one that redirects invalidates the tag.

Option 1: an extension (recommended)

This is the usual route, because the real work is not printing tags but knowing which URL corresponds to the same entity in another store view, translated url_key included. Marketplace extensions read your store views and build the group automatically for the homepage, categories, products and CMS pages, without touching templates.

When choosing one, check it covers these four points, because not all of them do:

  • It generates the self-reference, not just links to the other store views.
  • It lets you designate one store view as x-default.
  • It omits products not visible in a store view instead of generating a tag pointing at a 404.
  • It respects url_keys translated per store view rather than assuming the same path.

Option 2: your own layout XML

If the catalogue is identical across store views and paths match, you can inject the tags from your theme with layout XML and no extension. That is viable on stores with a stable structure and few languages.

xml
<!-- app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      layout="1column"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <link src="" rel="alternate" hreflang="en-US"
              href="https://example.com/en/"/>
        <link src="" rel="alternate" hreflang="fr-FR"
              href="https://example.com/fr/"/>
        <link src="" rel="alternate" hreflang="x-default"
              href="https://example.com/en/"/>
    </head>
</page>

This layout applies the same group to every page that inherits it, so it only works for fixed URLs like the homepage. Applying it globally would make every product page declare the other languages’ homepage as its alternate, which is worse than having no hreflang at all.

For dynamic pages you need a custom block that resolves the equivalent URL in each store view from the current product or category. By the time you reach that point you are writing the extension: installing one is almost always cheaper.

Magento-specific errors

SymptomCauseFix
No hreflang tags at allMagento does not generate them nativelyInstall an extension or add the layout
Tags pointing at 404 pagesProduct not visible in that store viewExclude unavailable products from the group
Wrong language codeLocale misconfigured on the store viewFix the locale under Locale Options
URLs with and without store code mixedAdd Store Code half-enabledPick one convention and declare the URL that returns 200

Verify store view by store view

In Magento the volume works against you: a misconfigured extension generates wrong tags across thousands of pages at once. Take one product page across every store view and validate the URLs together before signing off on the configuration. Then repeat with a category and a CMS page, because extensions do not always treat the three page types the same way.

Try the tool for free

Analyze your URLs with Hreflang Validator by iRankly. No sign-up, no credit card.

Use tool for free

If you are on another platform, or want the conceptual detail of what each attribute does:


Try the tool for free

Analyze your URLs with Hreflang Validator by iRankly. No sign-up, no credit card.

Use tool for free