The hreflang attribute tells Google about available translations for a given page or post. When used correctly, it can dramatically improve search engine positioning, because Google will understand which translation to display for people in different places.
- Hreflang Attributes Help Google Display the Right Translation in Search Results
- Required Conditions for Hreflang to Work Correctly
- How WPML Creates Hreflang Tags
- How to Add Hreflang Attributes with WPML
- Learn More
When you search for something in Google, Google knows where you are located and which language you prefer. It does this through your IP address and browser settings.
The hreflang attributes allow websites to tell Google which translations (or country-specific content) you offer for people in different places who speak different languages.
Using hreflang attributes, you can display language-specific and country-specific content to people speaking these languages and in these countries.
Of course, for this “magic” to happen, some conditions have to be met.
First and foremost, be sure to only use hreflang tags to connect content that is essentially the same, just in different languages or localized for different countries.
If you use hreflang tags to tie together content that’s significantly different, you will only confuse Google. As a result, don’t expect any good results.
HTML documents include a header and a body. The hreflang tags must appear inside the header. They should look like the following example:
We understand that hreflang attributes indicate to Google about available translated or localized content. So it follows that if item-B is equivalent to item-A, then also item-A is equivalent to item-B. That’s pretty obvious.
This means that items connected using hreflang need to form complete sets. All items in the set have to link to all other items. Google also requires that items link to themselves.
For example, a piece of content is available in English, French, Spanish, and Italian, the English version has to link to the translated French, Spanish, and Italian versions and also to itself.
The value of the hreflang attribute identifies the language and, optionally, the region of an alternate URL.
If you have geographically unspecified users, the hreflang follows a two-letter format according to standard codes. If you have specific URLs for users in different regions, a second two-letter value corresponds to the region and should be set according to the international rules.
- fr: French content, independent of region
- fr-CA: French content for users from Canada
- fr-FR: French content for users from France
Which option should you choose? This depends on how your site’s content is organized:
- If your site has versions of your content in the same language but with minor differences based on locale (like different currencies, contact details or purchase instructions), you should use region-specific hreflang attributes. This tells Google that the content is not duplicate, but intended for different countries.
- If your site has content in several languages, but not specialized for different countries, you should use hreflang attributes with just language information.
WPML retrieves the hreflang value from the setting found at WPML → Languages and clicking on Edit Languages.
New installations of WPML already have the hreflang properly filled. However, WPML always tries to adjust these codes when rendering the hreflang elements and find the best and more complete value. To do this, it will sometimes replace the underscores with a dash and make the string lowercase.
For example, if you use the value fr_ca, WPML will transform it into fr-CA.
However, even though WPML does its best to render the right hreflang, it is not able to check if it has valid format or not. For example, an fr-CA hreflang should match the language-country structure as we mentioned before. WPML is not able to warn you if you are using an invalid country-language format instead.
If WPML cannot find a suitable value, it won’t render a hreflang for that language.
When you use WPML to build multilingual WordPress sites, WPML will add hreflang to the HTML header as close as possible to the beginning of the
<head> section. You can adjust this by going to WPML → Languages → SEO Options.
The option to display the hreflang link attributes at lower priority is a fallback, which is useful if some themes trigger WPML initialization too early. In addition to the position of these tags in the header, you can control the language/locale codes that WPML will output in the tags.
These tags will automatically link to all available translations and to the same language. If an item is translated to only part of the site’s languages, WPML will include hreflang links only to these languages.
For a comprehensive guide to hreflangs we suggest reading Ahref’s easy guide for beginners.