If your WordPress site serves content in multiple languages or targets different regions, implementing hreflang tags is essential. Without them, search engines may show the wrong language version in search results or treat your translated pages as duplicate content. Here's how to implement them correctly.
Method 1: Using WPML (Recommended for Multilingual Sites)
WPML is the most popular multilingual plugin and automatically handles hreflang tags:
- Install and activate WPML Multilingual CMS.
- Go to WPML → Languages and configure your languages.
- WPML automatically adds hreflang tags for all translated pages.
- Verify the output by checking your page source for
<link rel="alternate" hreflang="...">tags.
WPML also handles the x-default tag automatically, pointing to your default language.
Method 2: Using Polylang
Polylang is a free multilingual plugin that also generates hreflang tags:
- Install and activate Polylang.
- Set up your languages under Languages → Languages.
- Create translations for your content by linking posts/pages across languages.
- Polylang automatically outputs hreflang tags for all linked translations.
Method 3: Using Yoast SEO + WPML/Polylang
Yoast SEO integrates with both WPML and Polylang to generate optimized hreflang tags. When both plugins are active, Yoast takes over hreflang generation with additional validation.
Method 4: Manual Implementation
For custom setups, add hreflang tags manually in your theme:
function add_hreflang_tags() {
if (is_singular()) {
$translations = array(
'en' => 'https://example.com/en/' . get_post_field('post_name'),
'de' => 'https://example.com/de/' . get_post_meta(get_the_ID(), '_de_slug', true),
);
foreach ($translations as $lang => $url) {
if (!empty($url)) {
echo '<link rel="alternate" hreflang="' . esc_attr($lang) . '" href="' . esc_url($url) . '" />' . "\n";
}
}
// x-default fallback
echo '<link rel="alternate" hreflang="x-default" href="' . esc_url($translations['en']) . '" />' . "\n";
}
}
add_action('wp_head', 'add_hreflang_tags');Common Pitfalls to Avoid
- Missing bidirectional links — Every page must link to all its translations, including itself. If page A (English) links to page B (German), page B must also link back to page A.
- Non-canonical URLs — Always use the canonical URL in hreflang tags. If a page has
rel="canonical", the hreflang href must match it. - Incomplete coverage — If you have 3 languages, every page variant must have 3 hreflang tags (one per language) plus the x-default.
- Regional vs. language targeting — Use
defor German-speaking users everywhere, orde-DE,de-AT,de-CHfor specific countries.
Verifying Your Implementation
- Run your site through InspectWP — it detects all hreflang tags and lists each language variant.
- Check Google Search Console under International Targeting for hreflang errors.
- Manually inspect the
<head>of each language version to confirm bidirectional links.
Hreflang in XML Sitemaps
For large sites, you can also declare hreflang in your XML sitemap instead of (or in addition to) HTML tags. WPML and Polylang support this automatically. The XML sitemap approach is particularly useful for sites with thousands of pages.