Fix Guide

How to Implement Hreflang Tags in WordPress

February 8, 2026

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:



  1. Install and activate WPML Multilingual CMS.

  2. Go to WPML → Languages and configure your languages.

  3. WPML automatically adds hreflang tags for all translated pages.

  4. 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:



  1. Install and activate Polylang.

  2. Set up your languages under Languages → Languages.

  3. Create translations for your content by linking posts/pages across languages.

  4. 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 de for German-speaking users everywhere, or de-DE, de-AT, de-CH for specific countries.



Verifying Your Implementation



  1. Run your site through InspectWP — it detects all hreflang tags and lists each language variant.

  2. Check Google Search Console under International Targeting for hreflang errors.

  3. 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.

Check your WordPress site now

InspectWP analyzes your WordPress site for security issues, SEO problems, GDPR compliance, and performance — for free.

Analyze your site free