Skip to content

Add hreflang alternate links to sitemap.xml#99

Merged
c4software merged 2 commits into
masterfrom
claude/issue-fix-pntxk3
Jul 24, 2026
Merged

Add hreflang alternate links to sitemap.xml#99
c4software merged 2 commits into
masterfrom
claude/issue-fix-pntxk3

Conversation

@c4software

Copy link
Copy Markdown
Owner

Summary

  • Closes How to add hreflang tags #83
  • Each page's <link rel="alternate" hreflang="..." href="..."> tags are now read and added to that page's sitemap entry as <xhtml:link rel="alternate" hreflang="..." href="..."/>, following Google's localized-versions sitemap format
  • Added the xmlns:xhtml namespace to the sitemap header, required for <xhtml:link> elements
  • This is on by default (same opt-out convention as the existing noindex/canonical handling); pass --no-hreflang to disable it

Test plan

  • Ran the crawler against a local test server with pages containing real hreflang alternate links and confirmed the correct <xhtml:link> entries appear in the output sitemap
  • Confirmed pages without any hreflang attribute (no <link> tags at all, rel="stylesheet", rel="canonical", and rel="alternate" RSS links without hreflang) produce no <xhtml:link> output — no regression for sites that don't use hreflang
  • Confirmed --no-hreflang disables the feature entirely

Generated by Claude Code

claude added 2 commits July 24, 2026 13:02
Closes #83. When enabled, <link rel="alternate" hreflang="..." href="...">
tags found on each page are added to that page's sitemap entry as
<xhtml:link> alternates, following Google's localized-versions sitemap
format.
Following the same opt-out convention as noindex/canonical handling.
Use --no-hreflang to disable adding <xhtml:link> alternates read from
<link rel="alternate" hreflang="..."> tags. Verified pages without a
hreflang attribute (no <link> tags, stylesheet/canonical/RSS
alternate links) produce no <xhtml:link> output, so there's no
regression for sites that don't use hreflang.
@c4software
c4software merged commit c5745d4 into master Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to add hreflang tags

2 participants