Guide
Setting up hreflang correctly
Language codes, self references, return links and x-default: the four basics of a working hreflang set.
A hreflang tag tells search engines such as Google which pages carry the same content in another language or for another region, so they can show each visitor the version in their language. hreflang tags work as a set, with one tag per language version: every page lists itself and all of its language versions, and every version confirms the others. On every page, the search engine thus learns the language of the page itself and where its translations are.
This guide covers the four findings in a scan report about that basic set. hreflang is a signal, not a ranking factor: a correct set helps search engines choose the right version, but it does not improve rankings by itself.
Invalid language code
Finding in the report: HREFLANG_INVALID_CODE
What it means
A hreflang value is not a code search engines understand. Google accepts a language code from ISO 639-1, such as de, optionally followed by a region code from ISO 3166-1 Alpha 2, such as de-AT, and the special value x-default. A region on its own is not valid.
Search engines ignore a link with an invalid code. The language version it points to is then missing from the set.
Typical causes
- An underscore instead of a hyphen, such as
en_US. WordPress uses this form internally, so it easily ends up in templates. - A wrong region code, such as
en-UK: the code for the United Kingdom isGB. - A country code where a language code belongs, such as
atfor Austria orjpfor Japanese (the language code isja). - A language name or a made-up value, such as
englishoren-world.
How to check
- The finding in the scan report shows the value exactly as the page declared it and, where the scanner can tell, a suggested value.
- Check the value against the rule: language code, optionally a hyphen and a region code.
- Find out where the value comes from: the language settings of your CMS or translation plugin, or your own template.
How to fix
- Correct the language code where it is generated. In a plugin this is usually the code entered for each language.
- Use the same code for a language version on every page and in every source (HTML, HTTP header, sitemap).
hreflang="de" valid: German
hreflang="de-AT" valid: German for Austria
hreflang="x-default" valid: the fallback
hreflang="en_US" invalid: underscore
hreflang="en-UK" invalid: the region code is GB
hreflang="at" invalid: a region on its own
How to confirm the fix
- Open the page source and check the corrected values in the hreflang tags.
- Scan again: the finding disappears from the report once the scanner no longer sees the invalid value.
Page does not list itself
Finding in the report: HREFLANG_MISSING_SELF
What it means
Every page in a set has to include itself, with its own language code, in its hreflang links. Google says so explicitly: each language version must list itself as well as all other language versions.
Without the self reference, search engines may ignore the whole set of hreflang tags.
Typical causes
- A template that leaves out the current language when it loops over the languages.
- A hand-written list that was copied from another language version and not adjusted.
- The self reference uses a different address than the one the page is served at: http instead of https, with or without www, with or without a trailing slash.
How to check
- Open the page and view its source code, or the sitemap if the hreflang links are there.
- Look for a hreflang link whose address is exactly this page's address.
- Compare the address character by character: protocol, www, path and trailing slash all count.
How to fix
- Add a hreflang link to the page itself with its own language code.
- Use the full address (with https://) that the page is actually served at, the same one its canonical link names.
How to confirm the fix
- Check the self reference in the page source.
- Scan again: the finding disappears once the scanner sees the self reference.
Linked page does not link back
Finding in the report: HREFLANG_MISSING_RETURN
What it means
hreflang links have to be confirmed from both sides. If page A names page B as its German version, page B has to name page A in return. Google ignores links that two pages do not both confirm.
The finding names the page that sets the link and the linked page that does not link back. The scanner only reports it when it could fetch and evaluate the linked page.
Typical causes
- The two pages are not connected as translations in the CMS or translation plugin, for example because one was created as a separate page.
- The linked page links back to a different address of this page, such as an old URL that now redirects or an address with parameters.
- The two pages declare their links in different places, for example one in the HTML and the other only in an outdated sitemap.
How to check
- Open the linked page named in the finding and view its hreflang links.
- Look for a link back to exactly the address of the page that reported the finding.
- In the CMS, check whether the two pages are connected as translations of each other.
How to fix
- Connect the two pages as translations in your CMS or plugin; it then writes both directions.
- If you write the links yourself, add the return link on the linked page, with the exact address of this page.
<!-- on https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="https://example.com/en/">
<link rel="alternate" hreflang="de" href="https://example.com/de/">
<!-- on https://example.com/de/ -->
<link rel="alternate" hreflang="en" href="https://example.com/en/">
<link rel="alternate" hreflang="de" href="https://example.com/de/">
How to confirm the fix
- Check the hreflang links in the source of both pages.
- Scan again: the finding disappears once both pages point to each other.
hreflang x-default missing (optional)
Finding in the report: HREFLANG_X_DEFAULT_MISSING
What it means
hreflang="x-default" names the page search engines show to visitors whose language or region none of your language versions targets. Google recommends this fallback page but does not require it. It was designed mainly for a language selection page; it can also be a home page that redirects visitors, or the version you consider the most general.
The scanner reports a missing x-default as information, not as an error.
Typical causes
- The website or plugin does not write x-default unless you ask it to.
- Nobody has decided which page should be the fallback.
How to check
- Decide whether you have a sensible fallback: a language selection page, or a version that suits visitors from anywhere.
- If you do, check whether an x-default link already exists in the page source or the sitemap.
How to fix
- If you have a fallback page, add a link with
hreflang="x-default"pointing to it to the set on every page. - If you have none, leave it as it is: the finding is only a note.
How to confirm the fix
- Check the page source or the sitemap for the x-default link.
- Scan again: the note disappears once x-default is present.
Setup in WordPress, Weglot, Shopify, Joomla & co.
WordPress + WPML
WPML writes the hreflang links itself, for content that is connected as a translation. A missing return link usually means that two pages are not linked as translations of each other in WPML.
With Yoast SEO or Rank Math, WPML puts the hreflang links into the XML sitemap by default, not into the page's <head>. If you cannot find them in the page source, look at the source code of the sitemap. To have them in the <head> instead, WPML documents the constant WPML_SEO_ENABLE_SITEMAP_HREFLANG and the setting “Display alternative languages in the HEAD section” under WPML → Settings → URLs and SEO.
The hreflang code of each language, including a region such as fr-ca, is set under WPML → Settings → Languages by editing the language. WPML does not warn about an invalid value.
More on this: WPML: why your hreflang tags are no longer in the page source
Sources: WPML: Adding hreflang (external link) · WPML: Yoast SEO Multilingual (external link)
WordPress + Polylang
Polylang adds the hreflang links automatically for content that is linked as translations. A page without a linked translation has no partner that could link back.
The hreflang code comes from the language's locale, written with a hyphen: en_ZA becomes en-ZA.
Polylang adds x-default only to the home page, and only when the root address redirects to a language. For x-default on other pages, Polylang documents the filter pll_rel_hreflang_attributes.
WordPress + TranslatePress
TranslatePress adds hreflang links for every language of the website automatically, in both directions.
x-default is an option: Settings → TranslatePress → Advanced → Miscellaneous, “Enable the hreflang x-default tag for language”.
To change the code of a single language, TranslatePress documents the filter trp_hreflang.
Sources: TranslatePress: hreflang in WordPress (external link) · TranslatePress: change hreflang localization (external link)
Weglot
Weglot adds the hreflang links to the page's <head> automatically and gives each language its own path, such as /de/.
Weglot does not add x-default by default. For WordPress it documents the filter weglot_href_lang to add it.
Shopify
Shopify generates the hreflang links automatically from your markets and languages, but only for versions with their own domain, subdomain or subfolder. If all markets use the same address, there are no versions to declare.
x-default points to your primary domain, and the sitemaps contain the market addresses with hreflang as well.
The automatic links can be switched off under Online Store → Preferences. Do that only if a theme or app writes its own; otherwise two sets may contradict each other.
Sources: Shopify Help: SEO for international markets (external link)
Joomla
In Joomla's built-in multilingual setup, the plugin System – Language Filter writes the alternate links when its option “Add Alternate Meta Tags” is on.
The same plugin has an option for an x-default link and lets you choose the language it points to. Labels may differ slightly between Joomla versions; check the plugin's settings in your administrator.
Sources: Joomla issue tracker: x-default in the language filter plugin (external link)
A website with its own code, or a simple site without a database
Put one <link rel="alternate" hreflang="…" href="…"> per language version into the <head> of every version, including the page itself. Google requires full addresses, including https://.
Generate the set in your code from one list of versions, so that every page gets the same list and return links cannot drift apart.
Declare the links in one place: in the HTML, in the HTTP header or in the sitemap. Google treats the three as equivalent and gains nothing from combining them.