Check 23.13 · Hreflang and regional variants

Automate annotations through the CMS

Have the CMS or framework generate hreflang annotations from translation links: WordPress, Shopify, PrestaShop, Drupal, Laravel, Next.js.

Priority
Critical
Difficulty
Intermediate
Estimated time
2 h to 2 days
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

hreflang annotations should never be written by hand, page by page. The CMS or framework generates them from a single piece of information: which pages are translations of one another. Once the task is done, publishing, unpublishing or renaming a translation automatically updates the annotations of every version of the page, with no human intervention.

Why it matters

An hreflang annotation only works if it is correct on every page in the group. Google says so explicitly: each version must list all the others and itself, and if two pages do not point to each other, the annotations are ignored. On a 200-page site in four languages, that means 800 pages each carrying four or five links: more than 3,000 links to keep up to date.

Maintained by hand, these lists diverge from the first change: a newly added translation only appears on the page that was just created, a translated slug changes without the other versions following, a deleted page stays announced everywhere. The errors are silent: the page displays normally, only the search engine ignores the group.

Automation shifts the question. It is no longer about copying URLs, but about keeping the translation relationship up to date in the CMS (the “group” of equivalent pages). The annotations, the multilingual sitemap and the language switcher all follow from it.

What it improves

  • Reliable annotations Reciprocity, self-reference and absolute URLs are guaranteed by code, not by vigilance.
  • Use by search engines Google more often serves the version suited to the user's language and country when the group is consistent.
  • Maintenance time A published translation appears everywhere at once.
  • Consistency across methods HTML, HTTP headers and sitemap can be produced by the same function.
  • Generative engines None documents any use of hreflang. The effect is indirect, through the Google and Bing indexes that some of them use.
  • Rankings No direct effect. hreflang chooses which version to show; it does not make a page rank higher.

How to check

Read the annotations served by two versions of the same page:

curl -s https://example.com/fr/tarifs/ | grep -o '<link[^>]*hreflang[^>]*>'
curl -s https://example.com/de/preise/ | grep -o '<link[^>]*hreflang[^>]*>'

Expected result: both commands return exactly the same list, with absolute URLs, one line per published version (including the page itself) and at most one x-default line.

Then test the lifecycle, which is the real test of automation:

  1. Publish a test translation (in Italian, for example) of an existing page.
  2. Reload the other versions after purging the cache: the it line must appear without any other action.
  3. Unpublish the translation: the line must disappear everywhere.
  4. Change the slug of one version: the new URL must be picked up everywhere.

For a site-wide check, crawl with Screaming Frog with hreflang storage and crawling enabled (Configuration > Spider). The Hreflang tab flags, among other things, missing return links, missing self-references and targets that are non-canonical or set to noindex.

How to implement

Before you start

Whatever the tool, the generation rules are the same:

Rule Consequence in the code
Single source Annotations are computed from the translation group, never from a list written in the template
Truly equivalent pages No annotation to a language's home page when the page is not translated
Publishable targets only Exclude drafts, private pages, noindex pages and pages whose canonical points elsewhere
Self-reference The current page appears in its own list
Absolute URLs Production protocol and domain, even on staging or in a scheduled task
Valid codes fr, fr-FR, en-GB, never fr_FR (WordPress locale format) or en-UK
Single x-default To the language selection page or the fallback version, only once
Nothing if there is only one version A page with no translation needs no annotation

Also choose a single output method per content type (tags in the <head>, HTTP header or sitemap). If you combine several, generate them with the same function: see check consistency across HTML, HTTP header and sitemap methods (opens in a new tab).

Warning: do not stack two generators. A multilingual plugin plus a translation app, or Shopify's native tags plus tags added in the theme, produce two competing lists that end up diverging.

WordPress

Versions WordPress 6.8 and later; WPML 4 and 5, Polylang 3, TranslatePress 3, Weglot 6.

WordPress does not handle multiple languages without a plugin, and neither Yoast SEO nor Rank Math produces hreflang annotations itself: the multilingual plugin takes care of it.

  • WPML: the option to display alternative languages in the HEAD section (on by default) is in WPML > Settings, URLs and SEO section, since WPML 5; in WPML > Languages > SEO Options in WPML 4. The x-default points to the default language set in WPML; the wpml_hreflangs filter lets you modify the list. With the WPML SEO module and the Yoast SEO or Rank Math sitemap, WPML moves the annotations into the sitemap and turns off the HEAD option: check where they are output.
  • Polylang: tags are produced automatically for each linked translation. The pll_rel_hreflang_attributes filter lets you add an x-default or a regional code, in a small custom plugin or the child theme's functions.php:
add_filter('pll_rel_hreflang_attributes', function (array $hreflangs): array {
    if (! isset($hreflangs['en'])) {
        return $hreflangs;
    }

    $hreflangs['x-default'] = $hreflangs['en'];

    return $hreflangs;
});

Check in the source code that Polylang does not already output an x-default in your configuration, to avoid a duplicate.

  • TranslatePress and Weglot: annotations generated automatically for the active languages. Weglot translates on the fly: make sure each language really has its own URL.

In every case, quality depends on how translations are linked: a page that is translated but not linked to the original in the editor will not appear in any group. Purge the page cache (WP Rocket, LiteSpeed Cache…) after each translation is published, otherwise the other versions keep serving the old list.

Shopify

Versions Shopify with Shopify Markets, all plans, November 2026.

With Shopify Markets and published languages, Shopify adds the hreflang tags itself, through the content_for_header object that the theme must call in the <head> of layout/theme.liquid. The sitemaps also include the published languages. Nothing to code.

Checkpoints:

  • translations go through Translate & Adapt or a compatible translation app;
  • no hreflang tag is hard-coded in theme.liquid or added by an app;
  • automatic generation can be turned off in Online Store > Preferences, in the social sharing and SEO section, automatic hreflang tags option. Only do so if you write your own tags, built from the localization Liquid object and not from hard-coded domains.

PrestaShop

Versions PrestaShop 8 and 9, Classic and Hummingbird themes.

The Classic and Hummingbird themes (Hummingbird is the default theme for new installations since PrestaShop 9.1) output the tags in templates/_partials/head.tpl, head_hreflang block, from the $urls.alternative_langs variable. To add an x-default, override this block in the child theme:

{block name='head_hreflang'}
  {foreach from=$urls.alternative_langs item=pageUrl key=code}
    <link rel="alternate" href="{$pageUrl}" hreflang="{$code}">
  {/foreach}
  {if isset($urls.alternative_langs['en-us'])}
    <link rel="alternate" href="{$urls.alternative_langs['en-us']}" hreflang="x-default">
  {/if}
{/block}

Replace en-us with the code of your fallback language as it appears in the source code. Clear the cache in Advanced Parameters > Performance after the change. A marketplace theme that rewrites head.tpl may have removed this block: check.

Magento

Versions Magento Open Source and Adobe Commerce 2.4.6 to 2.4.9.

Magento Open Source does not produce hreflang annotations out of the box. Use an extension that links store views together and generates the tags and the sitemap from the same mapping. Check that it excludes products that are disabled or not visible in a store view.

Drupal

Versions Drupal 10 and 11; Hreflang module 8.x-1.x, or 2.x from Drupal 11.1.

With the core Content Translation module, Drupal adds the alternate tags to the <head> of translated content pages, for published translations only. Pages that are not entities (views, listings) are not covered: the contributed Hreflang module fills this gap. Clear the caches (drush cr) after installation.

Joomla

Versions Joomla 5 and 6.

Enable multilingual associations, then in System > Plugins, open the “System - Language Filter” plugin: turn on Item Associations, Add Alternate Meta Tags and, if needed, the x-default tag by choosing its language. Articles, categories and menus must be associated across languages in Content > Multilingual Associations.

Wix

Versions Wix Multilingual, all plans, November 2026.

Wix Multilingual adds hreflang and x-default tags to multilingual pages by default. Nothing to configure, other than checking that each language is published and visible.

Webflow

Versions Webflow Localization, add-on to site plans, November 2026.

With Webflow Localization, hreflang tags are generated automatically on publishing, in the pages and in the generated sitemap. The localization settings let you turn them off to write your own, or set a base URL: keep automatic generation unless you have a specific need.

Laravel

Versions Laravel 11 to 13.

Laravel has no hreflang module: store the translation group in the database and generate the tags in a Blade component. Example with a translation_group column on the Page model:

// app/View/Components/Hreflang.php
namespace App\View\Components;

use App\Models\Page;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Hreflang extends Component
{
    /** @var array<string, string> */
    public array $alternates;

    public function __construct(Page $page)
    {
        $this->alternates = Page::query()
            ->where('translation_group', $page->translation_group)
            ->where('is_published', true)
            ->where('is_indexable', true)
            ->get()
            ->mapWithKeys(fn (Page $translation): array => [
                $translation->hreflang => route('pages.show', [
                    'locale' => $translation->locale,
                    'slug' => $translation->slug,
                ]),
            ])
            ->all();
    }

    public function render(): View
    {
        return view('components.hreflang');
    }
}
{{-- resources/views/components/hreflang.blade.php --}}
@if(count($alternates) > 1)
    @foreach($alternates as $hreflang => $url)
        <link rel="alternate" hreflang="{{ $hreflang }}" href="{{ $url }}">
    @endforeach
    @isset($alternates['en'])
        <link rel="alternate" hreflang="x-default" href="{{ $alternates['en'] }}">
    @endisset
@endif

Call <x-hreflang :page="$page" /> in the layout's <head>. route() produces absolute URLs; set APP_URL to the production domain so that commands and queues (sitemap generation) produce the same URLs as the pages. With the Laravel Localization package, LaravelLocalization::getLocalizedURL() returns a page's URL in another language, but only if routes are translated systematically.

Symfony

Versions Symfony 6.4, 7.4 and 8.x.

For localized routes where every language exists, Twig can rebuild the current page's URL in each language:

{% set route = app.request.attributes.get('_route') %}
{% set params = app.request.attributes.get('_route_params') %}
{% for locale, hreflang in {'fr': 'fr-FR', 'de': 'de-DE', 'en': 'en'} %}
    <link rel="alternate" hreflang="{{ hreflang }}" href="{{ url(route, params|merge({'_locale': locale})) }}">
{% endfor %}

This method assumes the page exists in every language with the same parameters. For content with translated slugs or missing translations, go through the translation relationship in the database, as in the Laravel example.

Next.js

Versions Next.js 15 and 16 (App Router).

With the App Router, declare the versions in alternates.languages in generateMetadata, based on the published translations returned by the CMS:

// app/[locale]/[slug]/page.tsx
import type { Metadata } from 'next'
import { getPublishedTranslations } from '@/lib/cms'

type Props = { params: Promise<{ locale: string; slug: string }> }

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { locale, slug } = await params
  const translations = await getPublishedTranslations(locale, slug)
  const languages: Record<string, string> = Object.fromEntries(
    translations.map((t) => [t.hreflang, t.path]),
  )

  if (languages['en']) {
    languages['x-default'] = languages['en']
  }

  return {
    alternates: {
      canonical: translations.find((t) => t.locale === locale)?.path,
      languages,
    },
  }
}

Set metadataBase in the root layout so that paths become absolute URLs. Since Next.js 15.2, when generateMetadata cannot be resolved at prerender time, Next.js streams the metadata and appends it to the end of the <body> for bots that execute JavaScript, Googlebot included; yet Google only accepts hreflang tags in the <head>. Prerender these pages (generateStaticParams), or turn off streaming with htmlLimitedBots: /.*/ in next.config.ts, then check the <head> in Search Console's URL Inspection tool. Reuse getPublishedTranslations in app/sitemap.ts (alternates.languages property) so that the sitemap says the same thing. With next-intl, the same logic applies.

Nuxt

Versions Nuxt 4, @nuxtjs/i18n module 10.

The Nuxt i18n module produces the tags with the useLocaleHead composable. Declare baseUrl (production domain) and each locale's language property in nuxt.config.ts; that property becomes the hreflang value. Then, in app/app.vue (app.vue at the root on a project that kept the Nuxt 3 structure):

<script setup>
useHead(useLocaleHead({ seo: true }))
</script>

For pages whose slugs come from a CMS, declare each page's translated parameters so that the alternate links do not point to a nonexistent slug.

Astro

Versions Astro 5 to 7, @astrojs/sitemap integration 3.

Astro does not generate hreflang tags for pages. Create a component that receives the list of published translations and include it in the layout's <head>; the @astrojs/sitemap integration offers an i18n option to add the alternates to the sitemap from the same locales.

Common mistakes

  • A list hard-coded in the template: every page announces the same languages, including those that do not exist, or points to each language's home page.
  • CMS locale codes copied as they are: fr_FR or en_UK are not valid hreflang values.
  • Two active generators: multilingual plugin plus translation app, or native tags plus theme tags.
  • Cache not purged: the new translation only appears on its own page; the other versions serve the old list for days.
  • Drafts and noindex pages included: the generator reads every translation instead of only published, indexable ones.
  • Staging URLs: a test domain or a relative URL ends up in the production annotations.
  • No lifecycle test: generation is checked at creation, never on unpublishing or a slug change. See update annotations when a translation is removed (opens in a new tab).

Frequently asked questions

Do Yoast SEO or Rank Math handle hreflang on WordPress?

No, Yoast SEO and Rank Math do not produce hreflang annotations themselves. On WordPress, multilingual plugins generate them from linked translations: WPML, Polylang, TranslatePress or Weglot. The two SEO plugins work alongside them and handle titles, canonicals and sitemaps. Just check that only one plugin produces the hreflang tags, to avoid two competing lists in the source code.

Do you need to add hreflang tags by hand on Shopify?

No, not if the store uses Shopify Markets and published languages. Shopify then adds the hreflang tags itself through the theme's content_for_header object, and includes the published languages in the sitemaps. Adding tags in the theme or through an app creates duplicates. Only turn off automatic generation in the online store preferences if you replace the tags entirely with your own.

How can you tell whether your hreflang annotations update automatically?

Test a page's full lifecycle. Publish a test translation, purge the cache, then check that every other version announces it. Then unpublish it and check that it disappears everywhere, then change a slug and check that the new URL is picked up. If even one of these steps requires manual work, the automation is incomplete and the annotations will eventually diverge.

Do automatic hreflang annotations improve SEO?

Not directly: hreflang is not a ranking factor. The annotations tell Google which version of a page to show depending on the user's language and country. Generating them automatically mainly ensures that they stay correct on every version, which is a condition for Google to use them. The gain shows in the right URL shown to the right audience, and therefore in click-through rate and conversion.

Updated on

Topic checklist (PDF)

And now?

In the “Hreflang and regional variants” topic

  1. Implement hreflang for equivalent pages
  2. Check reciprocity
  3. Include the self-referencing annotation
  4. Use absolute URLs
  5. Validate ISO 639-1 language codes
  6. Validate ISO 3166-1 Alpha-2 country codes
  7. Use en-GB rather than en-UK
  8. Use x-default if relevant
  9. Check that targets return HTTP 200
  10. Check that targets are indexable
  11. Exclude redirects and nonexistent pages
  12. Align hreflang and canonical
  13. Automate annotations through the CMS
  14. Update annotations when a translation is removed
  15. Use HTTP headers for PDFs if needed
  16. Check consistency across HTML, HTTP header and sitemap methods if combined
  17. Test same-language variants for different countries