Reading time: 11 minutes
Hreflang in WordPress is a set of tags that tells Google and Bing which pages are versions of the same content in another language. Each version lists itself and all the others. Below you will find hreflang in the sitemap, hreflang errors and a test.
In short
- Hreflang links the versions of a post in different languages. According to Google, it helps point each reader to the right version, but it does not detect a page’s language.
- Each version lists itself and all the others. Without return links, Google ignores the tags.
- Hreflang can go in an HTML tag, an HTTP header or the sitemap, and Google treats the three as equal. So pick a single method for hreflang in WordPress, preferably the plugin’s.
- The most common hreflang errors are a missing return link, an invalid code and a canonical in another language. A script checks reciprocity, the canonical and a 200 response.
What is hreflang and when does a bilingual WordPress blog need it?
Hreflang is a link attribute that tells Google two pages have the same content in different languages or regions. A bilingual WordPress blog needs it when it fully translates its posts. According to Google, this is one of the cases where indicating the versions is recommended.
According to Google, localized versions count as duplicates only if the main content stays untranslated. So a fully translated post is not a copy of the original. Even without hreflang, Google may find the versions on its own, but indicating them is usually better.
The attribute has a limit. Google does not use hreflang or the HTML lang attribute to detect the language of a page, because it reads the visible text. Therefore, hreflang does not fix a Spanish post that still has English passages.

Which attributes and language codes does hreflang accept?
Each hreflang tag in WordPress uses three attributes: rel="alternate", hreflang with the language code and href with the full URL. The code follows ISO 639-1 for the language, with an optional region in ISO 3166-1 Alpha 2, such as en-GB. Google accepts upper and lower case, but an uppercase region follows the standard.
<link rel="alternate" hreflang="en" href="https://www.example.com/blog/hreflang/" />
<link rel="alternate" hreflang="es" href="https://www.example.com/es/blog/hreflang/" />
Three rules prevent the most common hreflang errors. First, the URL must be complete, with https://, and not /blog/hreflang/. Second, a region alone is not valid: according to Google, be is the code for the Belarusian language, not for Belgium. Third, codes such as UK and EU have no effect, so use en-GB for the United Kingdom, not UK.
Google accepts a language code by itself, so en and es are enough for a US blog with one version per language. The region only matters when there are different versions of the same language. An example is en-US and en-GB, for a blog that shows prices in dollars to one audience and in pounds to the other. A blog for Germany and the UK would pair en-GB with de.
What is the hreflang x-default for in a bilingual blog?
The x-default is the reserved value for readers who speak a language the site does not offer. According to Google, it marks the fallback page for users whose language has no match. It was designed for pages that let the reader choose a language, and it needs no language code.
<link rel="alternate" hreflang="x-default" href="https://www.example.com/blog/hreflang/" />
In a blog without a selector page, point the x-default to the same post in the main language. Yoast explains that it can repeat the URL of one version. It is worth keeping both lines, because the language line declares the language of the page. The set of tags, by the way, is identical in every version.
Each hreflang plugin for WordPress handles the x-default in its own way. WPML says it supports an x-default attribute, but its documentation does not say how it appears in the sitemap. Polylang, according to its maker’s own blog, only generates the value on the home page. Therefore, check the source code instead of assuming.
Why do return links and the canonical decide whether hreflang works?
Hreflang only works when the pages point to each other. According to Google, if two pages do not point to each other, the tags are ignored. This stops a third-party site from declaring one of your pages as its own version. If the English post lists the Spanish one, the Spanish post must list the English one and itself.
The canonical enters the same equation. With hreflang, Google asks for each version to have a canonical in the same language, according to the canonicalization documentation. So the Spanish post cannot have a canonical pointing to the English post. Yoast adds that the hreflang URLs must be the canonical of each version, and that the opposite breaks the setup.
Google also prefers, as canonicals, the URLs that are part of an hreflang cluster. Thus a version outside the set may lose out.
In a WordPress blog with partial translation, hreflang can omit languages on some pages. Google processes the pairs that point to each other. What matters is to link each new translation to the original post.
Hreflang in HTML, in the header or in the sitemap: which to use in WordPress?
For hreflang in WordPress, use the method your multilingual plugin already offers, and use only one. For Google, an HTML tag, an HTTP header and a sitemap are equivalent. Using all three brings no benefit in search and makes maintenance harder.
- Tags in the
<head>: these are the plugin default. Yoast estimates about 1.5 KB per page with 20 languages, so the weight only matters on sites with many languages. With two languages, it is negligible. - XML sitemap: hreflang in the sitemap adds no page weight, and Yoast sees it as easier to change than the pages. Each
<url>lists all the versions, itself included, withxhtml:link. - HTTP header: it serves files that are not HTML, such as PDFs, according to Google.
With WPML SEO and the Yoast sitemap (this needs WPML’s Multilingual CMS or Multilingual Agency plan), WPML SEO writes hreflang in the sitemap. According to the WPML guide for Yoast, it then turns off the hreflang tags in the <head>, so search engines do not receive the same tags twice.
The two methods outside the page do not depend on JavaScript, as the guide to SSR vs CSR for SEO and AI shows.
How do you set up hreflang in WordPress with a plugin or with code?
There are two paths for hreflang in WordPress: a multilingual plugin that generates the tags, or your own code that prints them in the <head>. The plugin is safer, because it creates and updates the set with each translation. Code only pays off in small blogs without a translation plugin.
According to the WPML documentation, the plugin inserts and updates the tags on original and translated pages. It tries to adjust the format of the values, but it does not warn you if a code is invalid. Polylang uses the WordPress locale and swaps the underscore for a hyphen, so en_ZA becomes en-ZA. Because both descriptions come from the makers, who sell the plugins, check the result in the source code.
Without a translation plugin, store the language code and the URL of the pair in custom fields on each post. Then print the tags with the wp_head action. We did not run this snippet: test it on a staging WordPress before using it in production.
add_action( 'wp_head', function () {
if ( ! is_singular( 'post' ) ) {
return;
}
$id = get_queried_object_id();
$mine = get_post_meta( $id, 'hreflang_code', true );
$pair = get_post_meta( $id, 'hreflang_pair_url', true );
$pair_code = get_post_meta( $id, 'hreflang_pair_code', true );
if ( ! $mine || ! $pair || ! $pair_code ) {
return;
}
printf( '<link rel="alternate" hreflang="%s" href="%s" />' . "\n", esc_attr( $mine ), esc_url( get_permalink( $id ) ) );
printf( '<link rel="alternate" hreflang="%s" href="%s" />' . "\n", esc_attr( $pair_code ), esc_url( $pair ) );
}, 5 );
Fill in the three fields on both posts, with the language of the post itself and the URL and language of its pair. This is where the hreflang errors of manual code are born: one forgotten field breaks the return link. For the x-default, add a third line with the URL of the main language. Finally, do not enable the code if a plugin already writes hreflang, in the HTML or in the sitemap, because the two sets would add up.
What are the most common hreflang errors in WordPress?
The most common hreflang errors in WordPress are a missing return link, an invalid code, a canonical in the wrong language and a URL that changed. The first three come from the Google documentation. The last one appears when a post is deleted or redirected without updating its pair.
- No return link: Google ignores or misreads hreflang when page A points to B and B does not point to A.
- Invalid code: a region without a language, such as
be, or a region outside ISO 3166-1, such asUKandEU. - Canonical in another language: a Spanish post with a canonical to the English post takes the Spanish one out of the set.
- Relative URL: Google requires the full URL, with
https://, in the tags and in the sitemap hreflang. - Tag outside the
<head>or mixed: thelinktags belong in a well-formed<head>, with no other attributes, such asmedia, in the same tag. - Automatic redirect by language: Google recommends not redirecting the reader by presumed language, because this hides versions. Googlebot, by the way, usually comes from the US and does not send the Accept-Language header.
- Outdated pair: Yoast recommends checking the pair when a page is deleted and changing the hreflang URL when it is redirected.
How do you test hreflang in WordPress?
To test hreflang in WordPress and find the hreflang errors, check the HTML first, then reciprocity and, last, what Google crawled. There are four steps, and the first two run in seconds. They reveal the hreflang errors in return links and canonicals.
- Look at the raw HTML: the command below lists the tags of a URL. If nothing shows up, the plugin may be using hreflang in the sitemap: open
sitemap.xmland look forxhtml:link.
curl -s https://www.example.com/blog/hreflang/ | grep -io '<link[^>]*hreflang[^>]*>'
- Run a reciprocity script: the script below, in Python with no external libraries, opens the URL and each alternate. It flags a page that does not list itself, a response other than 200, a redirect, a swapped canonical, a missing return link and a missing x-default. Use
python check_hreflang.py URL.
import sys
import urllib.error
import urllib.request
from html.parser import HTMLParser
class Tags(HTMLParser):
def __init__(self):
super().__init__()
self.alt, self.canonical = {}, None
def handle_starttag(self, tag, attrs):
a = dict(attrs)
if tag != "link":
return
rel = (a.get("rel") or "").lower()
if rel == "alternate" and a.get("hreflang"):
self.alt[a["hreflang"].lower()] = a.get("href")
elif rel == "canonical":
self.canonical = a.get("href")
def read(url):
try:
r = urllib.request.urlopen(url, timeout=20)
except urllib.error.HTTPError as e:
r = e
t = Tags()
t.feed(r.read().decode("utf-8", "replace"))
return r.getcode(), r.geturl(), t
def check(url):
status, final, t = read(url)
print(f"{url} -> {status}, canonical: {t.canonical}")
if final != url:
print(f" ERROR: the URL redirects to {final}")
if t.canonical != url:
print(" ERROR: the canonical is not the page itself")
if url not in t.alt.values():
print(" ERROR: the page does not list itself")
if "x-default" not in t.alt:
print(" WARNING: no x-default")
for lang, href in t.alt.items():
if href == url or lang == "x-default":
continue
s, f, o = read(href)
if s != 200 or f != href:
print(f" ERROR {lang}: {href} returned {s} and ended at {f}")
if url not in o.alt.values():
print(f" ERROR {lang}: {href} does not link back")
if o.canonical != href:
print(f" ERROR {lang}: the canonical of {href} is {o.canonical}")
check(sys.argv.pop())
- Inspect the URL in Search Console: in the URL Inspection tool, click Test live URL and then View tested page. It shows the raw HTML returned.
- Use a third-party validator: Google cites Aleyda Solis’s generator and Merkle’s validator, but warns that it does not maintain or check these tools.
Google discontinued the International Targeting report and says it will keep using hreflang tags. Because the help page names no replacement report, test hreflang yourself after every plugin or permalink change.
Do Bing and AI answers use hreflang?
Bing recommends hreflang. In a December 2025 post on duplicate content, the Bing blog says localization creates duplicates. This happens when pages by language or region are nearly identical, with no useful differences for each market. To define language and region, it points to hreflang.
Older guides, such as Yoast’s from 2022, say Bing has no equivalent to hreflang. We could not confirm this on an official Bing page, and the 2025 post recommends hreflang. We also did not find how much weight the tag has against other signals. Therefore, do not promise any effect beyond what the documentation describes.
The same post links technical signals to AI. According to Bing, keeping metadata, internal links, redirects, canonicals and hreflang relationships aligned improves how search engines and AI systems read the pages. For the checking routine, see the technical SEO audit and the guide to adding your site to Bing Webmaster Tools.
Frequently asked questions
No. Google accepts omitting languages on some pages and processes the pairs that point to each other. A post without a translation has nothing to annotate. You only need to link each new translation to the original post, in both directions, with each page’s canonical in its own language.
The Google documentation does not promise a better position. According to it, hreflang helps show the most appropriate version of a page by language or region. It also does not detect the language, because Google reads the visible text of the page.
It is not recommended. Google asks you not to redirect automatically by presumed language, because this stops readers and search engines from seeing all the versions. Instead, offer links between the versions and let hreflang in WordPress point to the pages.
Main sources
- Google Search Central, how to tell Google about localized versions of a page (2026).
- Google Search Central, how to manage multi-regional and multilingual sites (2025).
- Google Search Central, how to specify a canonical URL (2026).
- Bing Webmaster Blog, duplicate content and AI search visibility (2025).
- WPML, how to add hreflang to a WordPress site (2025).
- Polylang, hreflang tag attributes and Polylang (2023).
- Yoast, hreflang: the ultimate guide (2022).
- Search Console Help, International Targeting report deprecated (2022).



