How to Add Hreflang Tags in WordPress
Add hreflang tags to WordPress using plugins (Yoast, WPML, Polylang, Rank Math) or manually. Step-by-step for each method.
WordPress doesn't add hreflang tags out of the box. You need either a multilingual plugin that handles it automatically, an SEO plugin with hreflang support, or manual code. Here's how each approach works.
Method 1: WPML (recommended for complex multilingual sites)
WPML (WordPress Multilingual Plugin) is the most widely used multilingual plugin for WordPress. It manages translated content and automatically outputs hreflang tags based on your translation structure.
Install and configure WPML
Install WPML from wpml.org (paid plugin, starts around $39/year). Run the setup wizard and select your default language and any additional languages you'll support.
Create translated versions of your content
WPML shows a translation panel on every post/page edit screen. Add translations for each language. WPML links these as alternates automatically.
Verify hreflang output
Once translations exist and you've set up your languages, WPML outputs hreflang tags in the HTML <head> automatically. View source on any translated page to confirm. You should see a full set of <link rel="alternate" hreflang="..."> tags including a self-reference.
WPML handles the return link requirement automatically -- every translated page gets the full cluster of hreflang tags. It also respects your canonical tags.
WPML and x-default
WPML doesn't add x-default by default. You can add it using a filter hook in your theme's functions.php or a custom plugin.
Method 2: Polylang
Polylang is a free alternative to WPML (with a paid Pro version). It has native hreflang support.
Install Polylang
Install from the WordPress plugin repository (free) or polylang.pro (Pro version). Go to Languages > Languages and add your supported languages.
Link translated content
In the post/page editor, Polylang shows a Languages metabox. Use it to link the current page to its translations in other languages.
Confirm hreflang output
Polylang outputs hreflang tags automatically once languages are configured and translations are linked. Check the source of a multilingual page.
Polylang Pro adds more URL configuration options (subdirectory, subdomain, separate domain per language). The free version supports subdirectory and language parameter approaches.
Method 3: Yoast SEO
Yoast SEO on its own doesn't generate hreflang tags -- that functionality is in Yoast SEO Premium when combined with a multilingual plugin. Yoast works alongside WPML and Polylang.
Yoast + WPML or Polylang
If you're using WPML or Polylang for translation management, Yoast SEO respects their hreflang output. You don't need to configure hreflang separately in Yoast -- let the multilingual plugin handle it.
Where Yoast matters: it controls the canonical tag. Make sure your Yoast canonical settings don't conflict with the hreflang tags your multilingual plugin outputs. See hreflang and canonical tags for how these interact.
Validate your WordPress hreflang
After setting up your plugin, use Hreflang Generator to confirm the tags are correct and complete.
Method 4: Rank Math
Rank Math SEO has built-in multilingual support. When used alongside WPML or Polylang, it picks up the language relationships those plugins define and outputs the hreflang tags.
In Rank Math's settings under General > Links, confirm the canonical URL settings are consistent with your language URLs. Rank Math + WPML is a common stack and they play together well.
Method 5: Manual via functions.php
If you're not using a multilingual plugin and want to add hreflang manually, you can output tags via your theme's functions.php (or a custom plugin -- functions.php changes get wiped on theme updates).
function add_hreflang_tags() {
// Only output on specific pages -- customize this condition
if ( is_front_page() ) {
echo '<link rel="alternate" hreflang="en" href="https://example.com/" />' . "\n";
echo '<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />' . "\n";
echo '<link rel="alternate" hreflang="de" href="https://example.com/de/" />' . "\n";
echo '<link rel="alternate" hreflang="x-default" href="https://example.com/" />' . "\n";
}
}
add_action( 'wp_head', 'add_hreflang_tags' );
This approach works for simple sites with a small number of pages but becomes hard to maintain as the site grows. You're responsible for keeping return links consistent across all page templates manually.
Manual hreflang scales poorly
Manual implementation via functions.php is error-prone on sites with many pages or frequent content changes. If you're serious about multilingual SEO, use a dedicated plugin.
WordPress Multisite considerations
On WordPress Multisite where each language is a separate site in the network, hreflang needs to reference URLs across different subsites. WPML has a multisite-compatible version. Polylang Pro also supports multisite networks.
If you're building hreflang across network sites manually, the process is the same as any cross-domain hreflang implementation -- just make sure you're using the correct absolute URLs for each site in the network.
Validate after setup
Whichever method you use, view source on several pages across different language versions and verify:
- Every page has a self-referencing hreflang tag
- Every page references all other language versions
- All URLs are absolute
- Language codes are valid (e.g.,
en-GBnoten-UK) - Canonical and hreflang self-reference match
Related Articles
Part of Boring Tools -- boring tools for boring jobs.
Generate perfect hreflang tags
Create and validate hreflang markup for your multilingual site. Free.