Skip to content

Multi-Region Hreflang XML Generator & Geotargeting Matrix

XML sitemap generator and validation script for multi-region websites. Validates bidirectional reciprocal tags, ISO 639-1 languages, and x-default fallbacks.

By Gordon Geraghty·MIT Licence·Updated: 21 August 2026·INTERMEDIATE·GitHub Mirror ↗

Common Hreflang Pitfalls in Multi-Region Stores

The most frequent hreflang defect is missing reciprocal confirmation links. If page A points to page B as its Australian variant, page B must return a reciprocal link pointing back to page A. Storing hreflang in XML sitemaps reduces HTML payload weight and streamlines maintenance.

Implementation Code & Script

XML Hreflang Cluster Generatorgenerate-hreflang-sitemap.tstypescript

Generates valid XML sitemap nodes with reciprocal alternate links and an x-default fallback.

interface HreflangEntry {
  lang: string;
  url: string;
}

export function buildHreflangUrlNode(loc: string, alternates: HreflangEntry[], xDefaultUrl: string): string {
  const links = alternates
    .map((a) => `    <xhtml:link rel="alternate" hreflang="${a.lang}" href="${a.url}" />`)
    .join('\n');
  const xDefault = `    <xhtml:link rel="alternate" hreflang="x-default" href="${xDefaultUrl}" />`;

  return `  <url>
    <loc>${loc}</loc>
${links}
${xDefault}
  </url>`;
}

How to cite and attribute this tool

MIT Licence

This resource is free, open and un-gated under the MIT Open Source Licence. You are encouraged to use, integrate and cite it with attribution:

Geraghty, G. (2026). Multi-Region Hreflang XML Generator & Geotargeting Matrix. Gordon Geraghty Resources Hub. https://gordongeraghty.com/resources/technical-seo/hreflang-configuration-matrix
BibTeX Format
@misc{geraghty_hreflang_configuration_matrix,
  author = {Geraghty, Gordon},
  title = {Multi-Region Hreflang XML Generator & Geotargeting Matrix},
  year = {2026},
  url = {https://gordongeraghty.com/resources/technical-seo/hreflang-configuration-matrix},
  note = {Head of Performance, Empire Amplify}
}

Changelog & Version History

  • v1.0.0Initial release of multi-region hreflang generator with reciprocal tag checking.