You can run hreflang on a multilingual WordPress site without Polylang or WPML. Put each language in its own folder as ordinary WordPress pages, keep a map of which pages are translations of each other, and let a small module print hreflang tags only for translations that are published. The same module can set the page language, the Open Graph locale and the language switcher. I built exactly that for a live music and event company in Spain: Ukrainian at the root, Russian, Spanish and English under /ru/, /es/ and /en/, with 137 new pages published on November 8, 2026.
What does Google need from hreflang?
Google's page on localized versions is short and strict. The rules that matter for a WordPress build:
- What it is for. Hreflang "will help Google Search point users to the most appropriate version of your page by language or region."
- Three equal methods. HTML link tags, HTTP headers or a sitemap. "The three methods are equivalent from Google's perspective."
- Every version lists every version. "Each language version must list itself as well as all other language versions."
- Links must go both ways. "If two pages don't both point to each other, the tags will be ignored."
- Full URLs. "Alternate URLs must be fully-qualified, including the transport method (http/https)."
- x-default. "The reserved x-default value is used when no other language/region matches the user's browser setting."
- Codes. The first code is the language, "followed by an optional second code that represents the region code."
One point surprises people. Google says it "doesn't use hreflang or the HTML lang attribute to detect the language of a page"; it detects language with its own algorithms. Hreflang tells Google which page is the alternate for which audience. It does not tell Google what language a page is in.
Google's guide to multi-regional and multilingual sites adds three rules for the site structure. It recommends "using different URLs for each language version of a page rather than using cookies or browser settings to adjust the content language." It says to "Avoid automatically redirecting users from one language version of a site to a different language version." And it lists subdirectories on one domain as "Low maintenance (same host)."
Why not Polylang on this site?
The site already had 54 Ukrainian pages in Google's index, built with Elementor Free and a hand-made header. My note in the module records the reason: Polylang on that setup would have rewritten the URLs of those 54 indexed pages. Changing the address of every page that already ranks is a site migration, with all its redirect risk, for a feature that only needed new pages added next to the old ones.
So the Ukrainian pages stayed exactly where they were, and each new language got a parent page (ru, es, en) with ordinary WordPress pages under it. No translation plugin, no URL changes to anything already indexed.
How does the module work?
It is one PHP file inside the site's own small plugin. It does four jobs, in its own words: it tells every other module which language the current request is in, prints hreflang alternates for pages that exist in more than one language, sets <html lang> and og:locale for /ru/, /es/ and /en/, and provides the header and breadcrumb strings in each language.
| Job | How it is done |
|---|---|
| Which language is this page? | The first segment of the URL path: /ru/, /es/ or /en/, otherwise Ukrainian |
| Which pages are translations of each other? | A map of groups written as paths, so it reads the same as URLs in Search Console. One group per page, for example the home page /, /ru/, /es/, /en/ |
| Hreflang | Printed only when a group has two or more published pages. Each published page in the group, plus x-default |
| Unpublished translations | A language missing from a group, or a page not published yet, gets no alternate and no switcher link |
| x-default | The Ukrainian page of the group, or the Spanish page when there is no Ukrainian one |
<html lang> |
ru-RU, es-ES or en-GB on the language folders |
og:locale |
The same locale, passed to the SEO plugin's Open Graph output |
| Schema language | The SEO plugin wrote inLanguage: "uk" on every page, so the module replaces it with the page's real language |
| Language switcher | UA, RU, ES, EN. The current language is marked, not linked. Other languages link to the same page in that language, or to that language's home page if there is no translation. A language appears only when its home page is published |
The hreflang part is small. A simplified version of it:
add_action( 'wp_head', 'site_i18n_hreflang', 4 );
function site_i18n_hreflang() {
$group = site_i18n_current_group(); // lang => path, published pages only
if ( count( $group ) < 2 ) {
return;
}
foreach ( $group as $lang => $path ) {
echo '<link rel="alternate" hreflang="' . esc_attr( $lang ) . '" href="' . esc_url( home_url( $path ) ) . '">' . "\n";
}
$default = isset( $group['uk'] ) ? $group['uk'] : $group['es'];
echo '<link rel="alternate" hreflang="x-default" href="' . esc_url( home_url( $default ) ) . '">' . "\n";
}
Two details make it safe. The tags print full URLs with https:// and the domain, which Google requires; a live city page on November 25, 2026 showed five tags, uk, ru, es, en and x-default, each with a full URL. And the group is filtered to published pages before anything prints, so the site never points Google to a draft that returns 404. Because every page in a group prints the same list, each page lists itself and all the others, and the return links are automatic.
Hreflang only for published pages, so Google never gets a 404
Because a map is a plan and a site changes one page at a time. The map listed translations before all of them were written. If hreflang pointed to a URL that did not exist yet, the other pages in the group would carry a broken alternate. Checking the post status first means a new translation joins its group on the day it is published and not before. The same check hides a language from the switcher until its home page is live.
Checks before and after the launch of 137 pages
Before the full launch. The first step, in October 2026, paired four Ukrainian city pages with their new Spanish versions. On the live site each pair showed hreflang uk, es and x-default, and the ES button led to the Spanish page for the same city. An earlier check of 12 live pages confirmed for each one: status 200, the right lang, four hreflang tags, a self canonical, and JSON-LD that parses.
At launch, November 8, 2026. 137 new pages went live: 53 in Russian, 40 in Spanish and 44 in English. Hreflang for uk, ru, es, en and x-default was present on the live pages. A render audit of 210 pages at two screen sizes found no real problems. 167 URLs were sent through IndexNow and the sitemaps were submitted in Search Console.
Why Spanish and English pages were worth building
Because Search Console showed Spanish searches landing on Ukrainian pages with zero clicks. The Spanish and English sections were written for those visitors instead of sending them to the Ukrainian homepage. One result is recorded in the event company case study: on October 14, 2026, a visitor filled in the form on a Spanish page, and it became a booking.
What are the common hreflang mistakes on WordPress?
From Google's rules above, and from what the module had to avoid:
- One-way tags. If the Spanish page names the Ukrainian one but not the other way round, Google ignores the pair.
- Relative URLs.
/es/is not enough; Google needshttps://and the domain. - Alternates to drafts or deleted pages. Filter to published pages.
- Redirecting by browser language. Google advises against it. Use a switcher and let the visitor choose.
- Translating only the menu. Google lists "Translating only the boilerplate text of your pages while keeping the bulk of your content in a single language" as something to avoid.
- Trusting the plugin's schema. Here the SEO plugin labeled every page as Ukrainian in structured data until the module overrode it.
If two language versions of a page start competing for the same search, that is a cannibalization problem, covered in the keyword cannibalization tool post. And if you are choosing between language folders and subdomains, the trade-offs are in subdomains and SEO.
FAQ
Do I need Polylang or WPML for hreflang? No. Google accepts hreflang as HTML link tags, HTTP headers or a sitemap, and a short function in a plugin can print the tags. A translation plugin is useful when you want a translation workflow in the editor; it is not required for the tags.
Does hreflang improve rankings? Google describes it as a way to "point users to the most appropriate version of your page by language or region." It is about showing the right version, not about ranking higher.
What should x-default point to? The version for visitors whose language matches none of yours. On this site it is the Ukrainian page of each group, or the Spanish page where no Ukrainian version exists.
Should I set html lang if Google ignores it?
Google says it does not use lang to detect a page's language. I set it anyway, with og:locale and the schema language, so every signal on the page agrees with the hreflang tags.
Folders or subdomains? Google lists subdirectories as low maintenance on the same host. This site uses folders because the Ukrainian URLs could stay where they were.
If you need a multilingual or multi-location site structured without breaking the URLs you already rank with, the free written diagnostic is the place to start.
Related: