Headless CMS hreflang: WordPress, Sanity, Contentful
How hreflang works in headless CMS setups: Sanity and Contentful translation models, WordPress and Shopify plugins, and how to check every cluster.

- Implementing hreflang correctly inside a CMS requires understanding how each platform handles language variants, URL routing, and metadata generation.
- WordPress supports hreflang through several plugins, but not all produce valid markup.
- Shopify's built-in internationalization supports markets per country or language.
- Sanity provides locale-aware content through its structured content model.
- Contentful's localization model maps each entry to a locale with a translation reference field linking variants.
- For any headless CMS, consider generating hreflang at the reverse proxy layer.
- CMS plugin or implementation produces self-referential markup on every page.
Implementing hreflang correctly inside a CMS requires understanding how each platform handles language variants, URL routing, and metadata generation. A misconfigured CMS plugin can inject broken hreflang markup across thousands of pages. This guide covers hreflang implementation in four major CMS ecosystems: WordPress, Shopify, Sanity (headless), and Contentful (headless) with 2026 best practices.
Introduction

Implementing hreflang correctly inside a CMS requires understanding how each platform handles language variants, URL routing, and metadata generation. A misconfigured CMS plugin can inject broken hreflang markup across thousands of pages. This guide covers hreflang implementation in four major CMS ecosystems: WordPress, Shopify, Sanity (headless), and Contentful (headless) with 2026 best practices.
The short answer
Hreflang in a CMS is a link cluster, not a plugin setting. Each language version must list itself and every other version with matching return links. WordPress and Shopify need plugin validation, while Sanity and Contentful build clusters from translation references in queries.
1. WordPress: plugins and custom solutions

WordPress supports hreflang through several plugins, but not all produce valid markup. The three most reliable approaches in 2026 are:
Polylang Pro generates <link> hreflang tags for each language variant and includes self-referential markup. It also adds <xhtml:link> entries in XML sitemaps. Verify that the "Hide URL language information for default language" setting is disabled if you use subdirectory paths.
WPML outputs hreflang via its wpml_hreflang filter and the &hreflang=1 URL parameter on sitemaps. WPML documents two output paths: the Display alternative languages in the HEAD section option writes hreflang links into the page head, and with Yoast SEO or Rank Math plus the WPML SEO add-on and the SEO plugin sitemap switched on, WPML SEO writes the links into the sitemap instead (https://wpml.org/documentation/getting-started-guide/language-setup/). Common WPML issues include missing return tags when a translation is in draft status and incorrect hreflang language codes for regional variants (e.g., en instead of en-US).
Custom implementation: A functions.php filter on wp_head can output hreflang links by reading a custom field per page. This gives full control but requires maintaining URL consistency across languages. Always validate the rendered head and sitemap before launch, because a plugin that stops outputting the tags still looks healthy in the admin screens.
2. Shopify: limitations and solutions

Shopify's built-in internationalization supports markets per country or language. The platform automatically generates hreflang tags for each market, but has notable limitations. Shopify only supports hreflang for markets created inside the Shopify admin; custom subdirectory setups produce no hreflang markup. Its hreflang output is hardcoded into the theme's <head> via {{ content_for_header }} and cannot be modified through Liquid alone. Shopify does not give you a template hook for that markup, so check the rendered page for every published language and market. If a market is missing from the markup, the cluster breaks, because Google requires each language version to list itself as well as all other language versions (https://developers.google.com/search/docs/specialty/international/localized-versions). If you need control Shopify does not give you, the workable escape hatch is a headless setup where hreflang is managed at the CDN or reverse proxy layer.
Hreflang output by CMS platform
| CMS | Where hreflang comes from | What to verify |
|---|---|---|
| WordPress with Polylang Pro or WPML | Plugin output in the page head or the XML sitemap | Self-referential markup and return links for every published translation |
| Shopify | Built-in markets output, hardcoded in the theme head | Every market created in the admin appears in the rendered markup |
| Sanity | GROQ queries joining documents on a shared translation ID | No stale references left behind by a deleted translation |
| Contentful | A translation reference field read in a GraphQL or REST query | Each linked entry maps to the right slug and locale code |
Verify the rendered head and sitemap on every platform, because a healthy admin screen can still ship broken markup.
3. Sanity (headless CMS)
Sanity provides locale-aware content through its structured content model. For single-document locale fields, query translation references and output <link> tags at build time using sanity-plugin-internationalization. For separate documents per locale, generate sitemaps with <xhtml:link> entries by joining documents on a shared translation ID. Sanity's GROQ queries can fetch all translation slugs in one pass. The key risk is stale hreflang references when a translation is deleted but the reference remains. Sanity documents two localisation models: field-level, where one document holds every language, and document-level, where a unique document version exists per language and references join the language versions together (https://www.sanity.io/docs/studio/localization).
4. Contentful (headless CMS)
Contentful's localization model maps each entry to a locale with a translation reference field linking variants. Include this field in your GraphQL or REST query, map each linked entry's slug and locale code to hreflang tags, and iterate over entries to build <xhtml:link> clusters for sitemaps.
5. Proxy-level hreflang generation
For any headless CMS, consider generating hreflang at the reverse proxy layer. This approach reads the Content-Language header or response body from the CMS API, injects <link> hreflang tags into the HTML response using edge-side includes (ESI), and generates XML sitemaps with hreflang annotations via a scheduled serverless function. This decouples hreflang logic from the CMS, making it easier to maintain consistency across multiple CMS backends during a migration (Hreflang.org, 2025).
Audit checklist
- [ ] CMS plugin or implementation produces self-referential markup on every page.
- [ ] No draft or unpublished translation breaks the hreflang cluster.
- [ ] Shopify markets created for all target regions; hreflang verified in template output.
- [ ] Headless CMS queries include translation references in hreflang generation.
- [ ] XML sitemaps contain
<xhtml:link>entries for all language-region pairs. - [ ] Proxy-level hreflang tested for injection correctness.
Common questions about hreflang in CMS platforms
Does Shopify generate hreflang tags automatically?
Yes, but only for markets created inside the Shopify admin. Custom subdirectory setups produce no hreflang markup at all.
Can WordPress output hreflang without a plugin?
Yes, a functions.php filter on wp_head can print the links from a custom field per page. That path requires consistent URLs across every language.
Where should hreflang live in a headless CMS?
Build it from translation references at build time, or generate it at the reverse proxy layer. The proxy approach reads the Content-Language header and injects link tags into the response.
What breaks a hreflang cluster most often?
A draft or deleted translation that leaves a missing return link. Validate the rendered head and sitemap before launch.
Sources and date
Last checked: 1 November 2026. Sources: Google Search Central localized versions documentation, the WPML language setup guide, and Sanity localization docs.
Conclusion
Hreflang implementation varies significantly across CMS platforms. WordPress and Shopify require plugin-level validation, while headless CMS platforms like Sanity and Contentful demand custom query patterns. Whichever platform you use, validate every hreflang cluster with an automated tool and verify the rendered head and sitemap.