What hreflang is and how it works on a multilingual site

hreflang tells search engines which language version of a page to show to whom. How to write it, where it goes, and how Joomla handles it.

The problem hreflang solves

A site in English, German and French has three versions of its About page. Google has to decide which one to show someone searching in German from Vienna. Most of the time it works that out from the language of the page itself.

It struggles where versions share a language. English pages for the UK and for the US, or German pages for Germany and for Switzerland, can be nearly identical. Google may then treat them as duplicates, pick one as the canonical, and show that one to everyone.

Translations are a different matter. Google does not count a German page and its English translation as duplicate content. For those, hreflang helps the right version reach the right reader. For same-language regional versions, it is often the only thing telling Google they are meant for different people.

What hreflang says

hreflang is a set of links. Each language version lists every version of the page, itself included, with a language code for each. The German page says, in effect, "I am the German version, the English one is over there, the French one is there."

Where it goes

Google accepts hreflang in three places and treats them as equivalent. Pick one.

In the page's <head>:

<link rel="alternate" hreflang="en" href="https://yoursite.com/en/about" />
<link rel="alternate" hreflang="de" href="https://yoursite.com/de/about" />
<link rel="alternate" hreflang="fr" href="https://yoursite.com/fr/about" />
<link rel="alternate" hreflang="x-default" href="https://yoursite.com/about" />

In an HTTP header, for files with no HTML head, such as PDFs:

Link: <https://yoursite.com/en/guide.pdf>; rel="alternate"; hreflang="en",
      <https://yoursite.com/de/guide.pdf>; rel="alternate"; hreflang="de"

In the XML sitemap:

<url>
  <loc>https://yoursite.com/en/about</loc>
  <xhtml:link rel="alternate" hreflang="en" href="https://yoursite.com/en/about"/>
  <xhtml:link rel="alternate" hreflang="de" href="https://yoursite.com/de/about"/>
</url>

Using two methods at once is allowed. I would not bother, because it doubles the number of places that can disagree with each other.

Language codes

The value is a language code from ISO 639-1, optionally followed by a region code from ISO 3166-1 alpha-2. So en, en-GB, en-US, de and de-CH all work.

Two mistakes come up again and again. en-UK is wrong, because the region code for the United Kingdom is GB. And a region cannot stand on its own, so you cannot target "everyone in Switzerland" with a country code alone.

x-default marks the page for everyone who matches none of the listed languages. That is usually a language chooser, or your main-language home page.

Common mistakes

Missing return links. If the English page points to the German one and the German page does not point back, Google ignores the pair. Every version has to list every other version.

Pointing at the wrong address. Each address in hreflang should be the canonical, indexable version of that page. A link to an address that redirects, carries noindex or has a canonical pointing elsewhere is wasted.

Tagging pages that were never translated. A privacy policy that exists only in English needs no hreflang. Only pages with real language versions do.

hreflang and Joomla

Joomla has handled multilingual sites in its core for years. You install content languages, give each article and menu item a language, and link translations to each other with associations.

Joomla's Language Filter system plugin can write the hreflang links in the page head, one per language plus x-default. The settings are "Add Alternate Meta Tags" and "Add x-default Meta Tag" in that plugin, so check that both are on. The plugin knows which pages are translations of each other from the associations, so link your translations there.

To check the result, open a translated article, view the page source and search for hreflang. If the links are there, point both ways and use the right codes, you are done.

How AI Boost for Joomla handles hreflang

Through the Multilang extension, included in every plan. Once you switch it on, it writes hreflang in the page head and in the sitemap, from Joomla's associations or from Falang's translations.

Joomla's Language Filter plugin can write a second set. You choose which set stays. By default AI Boost writes its own and removes the other. AI Boost writes no hreflang while Multilang is off, so it does not clash with the Language Filter's links.