WPML: why your hreflang tags are no longer in the page source
Have you looked for the hreflang tags in the page source of your WordPress website and found none? That is not necessarily an error. If your website uses WPML together with Yoast SEO or Rank Math, since June 2025 you will usually no longer find the hreflang tags in the page source, but in the XML sitemap.
On a multilingual website, hreflang tags tell search engines which pages in other languages correspond to a page. Google treats them the same whether they are in the page source, in the HTTP header or in the XML sitemap. All that matters is that they are complete and correct, and to check that, you need to know where to look.
Where WPML writes the hreflang tags today
Since version 2.2.0 of WPML SEO (June 2025), WPML adds the hreflang tags to the XML sitemap when the sitemaps of Yoast SEO or Rank Math are switched on. According to its own documentation, WPML switches off the hreflang tags in the page's <head> at the same time. This way the tags are in one place only.
If you switch off the sitemap of your SEO plugin, WPML writes the hreflang tags into the page's <head> again. If you switch the sitemap back on later, WPML says you have to switch off the tags in the <head> yourself; otherwise they will be in two places.
Is this worse for my rankings in Google or Bing?
At this point, many website owners wonder whether it makes a difference for their search engine optimization where the hreflang tags are. For Google, the answer is no. Google names three equivalent ways to declare hreflang tags, in the page's <head>, in the HTTP header or in the XML sitemap, and states that combining them brings no advantage.
What really matters is not the place, but the content: the hreflang tags have to be complete, match each other and point to the right addresses. If they are in two places, both have to say the same thing.
There is still a practical difference, for you rather than for the search engine: hreflang tags in the sitemap are not visible when you open the page source of a page. To check that everything is right, you need to know where to look. That is what the next section is about.
Bing does not mention hreflang in its Webmaster Guidelines. Google states that it determines the language of a page from its visible content. So make sure that each language version is really written in its language. According to Google, it does not use the lang attribute for this; for browsers, screen readers and translation tools, it should still state the language of the page.
How to look in the sitemap
You will find the address of your sitemap in the settings of your SEO plugin; it is often also listed in your website's robots.txt file. It is usually a sitemap index that points to several individual sitemaps, for example for pages and posts.
Open one of these sitemaps and look at its source code (in the browser, usually with Ctrl+U or Cmd+Option+U). According to WPML, the readable view that the browser shows first does not include the hreflang tags.
In the source code, each address has a block with its language versions. Each xhtml:link line with rel="alternate" is an hreflang tag: it states a language code and the address of that language version.
<url>
<loc>https://example.com/contact/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/contact/"/>
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/kontakt/"/>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/contacto/"/>
</url>
What has to be set correctly in the sitemap
The rules are the same as for hreflang tags in the page source: each language version refers to itself and to all other language versions, and each reference contains the address of the matching page in the right language.
Each language code appears only once per address and is complete, for example en-nz for English in New Zealand, not just nz.
What each error means and how to fix it is explained in the guides “Setting up hreflang correctly” and “Contradictory hreflang tags”.
Common errors
Watch out for these three cases:
- No hreflang tags in the sitemap: according to the WPML documentation, WPML adds the hreflang tags to the sitemap of Yoast SEO or Rank Math. If another plugin generates the sitemap that your
robots.txtnames, it may contain no hreflang tags. Check which plugin generates this sitemap and whether the hreflang tags are then in the page's<head>. - Tags in two places that contradict each other: if there are hreflang tags in the
<head>and in the sitemap, both have to name the same addresses. Otherwise it is unclear which one applies. - Shortened language codes: an older version of WPML SEO wrote only the country code into the sitemap with Rank Math or Yoast SEO, for example
nzinstead ofen-nz. WPML fixed this in version 2.2.3. Keep WPML SEO up to date.
Prefer them in the page source?
If you want the hreflang tags back in the page's <head>, WPML describes two steps: add the line define( 'WPML_SEO_ENABLE_SITEMAP_HREFLANG', false ); to the wp-config.php file, and switch on the setting “Display alternative languages in the HEAD section” under WPML → Settings → URLs and SEO → SEO Options.
For search engines, both options are equivalent. Choose one place, so that the information cannot contradict itself.
Checking the whole website
Manually, you can only check page by page. A website scan reads the hreflang tags from the source of every page it checks, from the HTTP header and from the XML sitemap. It checks whether the language versions name each other and whether the language codes are valid, and reports when the information in the <head> and in the sitemap differs.
The scan finds the sitemap through the Sitemap: line in the robots.txt file or at the address /sitemap.xml. If it finds none, the report says so. In that case, add the address of your sitemap index to robots.txt.
If neither the pages checked nor the sitemap contain a single hreflang tag, the report points this out. If your website has several languages, the hreflang tags are then missing entirely, for example because another plugin generates the sitemap (see “Common errors”).
The single page check, by contrast, reads only the page itself, not the sitemap. If it finds no hreflang tags, it says they may be in the sitemap and points to a scan of the whole website.
Related guides
Related articles
Further reading
- WPML: Using Yoast SEO with WPML (external link)
- WPML: URLs, slugs and SEO (external link)
- WPML SEO 2.2.0 (external link)
- WPML errata: incorrect hreflang value in sitemaps (external link)
- Google Search Central: Tell Google about localized versions of your page (external link)
- Google Search Central: Managing multi-regional and multilingual sites (external link)