Skip to content

Fix: Core sitemaps rendered with HTTP 404 status when no post. - #13240

Closed
tewariharish wants to merge 5 commits into
WordPress:trunkfrom
tewariharish:fix-sitemap-error
Closed

Fix: Core sitemaps rendered with HTTP 404 status when no post. #13240
tewariharish wants to merge 5 commits into
WordPress:trunkfrom
tewariharish:fix-sitemap-error

Conversation

@tewariharish

Copy link
Copy Markdown

https://core.trac.wordpress.org/ticket/65936

Trac ticket:

Use of AI Tools


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props harishtewari, adamsilverstein, adrianduffell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

* Prevents core from issuing a 404 status header on valid sitemap requests
* when no standard blog posts exist.
*
* @since 6.8.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since 7.1.1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the version
@adrianduffell

Copy link
Copy Markdown

This was discussed in today’s bug scrub for 7.1.1. We recommend closing it in favor of #13247 as that one doesn't need a filter. Your efforts on the PR are much appreciated though, @tewariharish 🙏

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test should be added for this.

* @param WP_Query $query The global WP_Query object.
* @return bool True to preempt 404 handling if a valid sitemap route is requested, original $preempt otherwise.
*/
public function prevent_sitemap_404( $preempt, $query ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function prevent_sitemap_404( $preempt, $query ) {
public function prevent_sitemap_404( $preempt, WP_Query $query ): bool {

I'm specifically not adding a type hint to $preempt because other plugins could provide something non-bool and cause a fatal error.

Comment on lines +279 to +283
if ( $query->is_main_query() && get_query_var( 'sitemap' ) ) {
if ( $this->sitemaps_enabled() ) {
return true;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified:

Suggested change
if ( $query->is_main_query() && get_query_var( 'sitemap' ) ) {
if ( $this->sitemaps_enabled() ) {
return true;
}
}
if (
$query->is_main_query() &&
get_query_var( 'sitemap' ) &&
$this->sitemaps_enabled()
) {
return true;
}

*
* @link https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
* @link https://developer.chrome.com/multidevice/android/installtohomescreen
* @link https://developer.chrome.com/blog/support-for-theme-color-in-chrome-39-for-android

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unrelated changes which could be opened in a separate PR for Core-65860.

@westonruter

Copy link
Copy Markdown
Member

Closing in favor of #13247. Thanks!

@westonruter westonruter closed this Sep 3, 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.

4 participants