Guide
hreflang tags: what they are and how to add them in WordPress
hreflang tags are lines in the head of a page that tell search engines which other languages the same page exists in, and where each version lives. They do not translate anything and they do not change how a page ranks. They help a search engine show a Spanish speaker your Spanish page instead of your English one.
What hreflang tags tell a search engine
When a page exists in more than one language, a search engine has to work out that the versions belong together. hreflang tags say it outright. Google describes them as the way to tell it about localized versions of your page, so that it can point each visitor to the version in their language.
Google does not use hreflang, or the HTML lang attribute, to detect what language a page is written in. It reads the text of the page for that. hreflang only connects the versions.
Google does not treat translated pages as duplicates of each other. Its documentation says localized versions are only considered duplicates when the main content stays untranslated.
What a correct set of hreflang tags looks like
Here is the set for a page that exists in English and Spanish:
<link rel="alternate" hreflang="en-US" href="https://example.com/about-us" />
<link rel="alternate" hreflang="es" href="https://example.com/es/sobre-nosotros" />
<link rel="alternate" hreflang="x-default" href="https://example.com/about-us" />
The same three lines appear on both pages. Google’s rules for a valid set are short:
- Each language version lists itself as well as every other version.
- The versions point to each other. If two pages do not both point to each other, the tags are ignored.
- Every address is complete, including
https://.
hreflang language and region codes
The value starts with a language code in ISO 639-1 format, such as es. A region code in ISO 3166-1 Alpha 2 format may follow it, such as pt-BR for Portuguese in Brazil. The region is optional: use it only when you have different pages for different countries.
Google supports only codes from those two lists. A code such as es-419, which other standards use for Latin American Spanish, is not supported. The value is not case sensitive.
What x-default is for
The reserved value x-default names the page to show when none of your languages matches the visitor. Google designed it for language selector pages and for home pages that choose a language, but it can be used on any page. Most sites point it at the version in their main language.
Common hreflang mistakes
- Missing return tags. Page A lists page B, but page B does not list page A. Google ignores the pair.
- No self reference. Each page must list itself too.
- Unsupported codes, such as
es-419. Only ISO 639-1 languages and ISO 3166-1 Alpha 2 regions count. - Short addresses.
/es/sobre-nosotrosis not enough: the address must be complete. - Three methods at once. hreflang can live in the HTML, in HTTP headers or in a sitemap. Google treats the three as equal and sees no benefit in combining them, so pick one.
How to add hreflang tags in WordPress
WordPress does not print hreflang tags on its own, because it has no record of which page is the translation of which. Something has to keep that record: a multilingual plugin, or your own code in the theme.
With Vabelon, you link each page to its translations in the editor, and the plugin prints the tags for you:
- A page with at least one published translation lists every language it exists in, itself included.
- An
x-defaultline points to the version in your default language. - A page with no translations prints no hreflang tags, so there is never a tag without a return tag.
- The code for each language comes from the hreflang column under Settings, then Vabelon.
The exact output is described in hreflang and page language.
How to check your hreflang tags
Open a translated page, view its source and search for hreflang. Then open the translation and check that it shows the same set. If both pages list each other and themselves, the tags are valid.