Fix Polylang sitemap URLs when "hide default language" setting is disabled#727
Draft
Fix Polylang sitemap URLs when "hide default language" setting is disabled#727
Conversation
Co-authored-by: sybrew <7662236+sybrew@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Sitemap issue with Polylang
Fix Polylang sitemap URLs when "hide default language" setting is disabled
Jun 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where language-specific sitemaps become inaccessible when Polylang's "The front page URL contains the language code instead of the page name or page id" setting is disabled.
Problem
When the Polylang setting "Hide URL language information for default language" is disabled, the front page URL structure changes, but TSF's sitemap endpoint generation doesn't account for this:
domain.com/lang_slug/sitemap.xmldomain.com/lang_slug/page-title/sitemap.xmlThis causes 404 errors when search engines try to access the sitemap URLs listed in robots.txt.
Root Cause
The
_polylang_register_sitemap_languages()function was making assumptions about URL structure, always generating endpoints like{language}/sitemap.xmlwithout considering how Polylang's settings affect the actual front page URL structure.Solution
Updated the sitemap endpoint generation to:
pll_home_url()function to get the actual language-specific home URLspll_home_url()is unavailableExample
Before: Always generates
es/sitemap.xmlregardless of Polylang settingsAfter:
es/sitemap.xmles/page-title/sitemap.xmlTesting
Fixes #675.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.