Make WordPress Core

Opened 4 years ago

Last modified 13 months ago

#51542 new defect (bug)

is_home() returns true for any component of an XML Sitemap

Reported by: madtownlems's profile MadtownLems Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Sitemaps Keywords:
Focuses: Cc:


It seems that any component of the core wp-sitemap.xml implementation returns true for the conditional tag is_home() (regardless even of if the homepage is set to display "Your Latest Posts" or "A static page").

For example, will return true.

This can easily cause problems with themes and plugins that use filters and the is_home() conditional tag to control which posts appear on the homepage.

Change History (5)

#1 @swissspidy
4 years ago

Possible duplicate of #51117

#2 @RavanH
2 years ago

Not sure this should be seen as a duplicate of #51117. Sure the default main query will set the is_home flag but when I modify the main query arguments (with query filter) to match the dedicated posts sitemap query, the is_home flag still gets set.

I checked and this is because of the following lines in wp-includes/class-wp-query.php starting at line 992:

if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed
                || ( defined( 'REST_REQUEST' ) && REST_REQUEST && $this->is_main_query() )
                || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_favicon ) ) {
        $this->is_home = true;

where the is_home flag is set when no others apply.

It seems to me we need a is_sitemap flag, in which case #51543 is more related :)

#3 @RavanH
2 years ago

This plugin should resolve the issue
Please let me know if there are still problems after applying the fix.

This ticket was mentioned in Slack in #core by swissspidy. View the logs.

13 months ago

#5 @Cybr
13 months ago

I think fixing any of #51542 (this ticket), #51543, or #51117 will resolve all these tickets.

Note: See TracTickets for help on using tickets.