Make WordPress Core

Opened 6 years ago

Closed 5 weeks ago

#51542 closed defect (bug) (fixed)

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

Reported by: MadtownLems Owned by: westonruter
Priority: normal Milestone: 7.1
Component: Sitemaps Version: 5.5
Severity: normal Keywords:
Cc: Focuses:

Description

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, www.site.com/wp-sitemap-posts-page-1.xml 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 (9)

#1 @swissspidy
6 years ago

Possible duplicate of #51117

#2 @RavanH
4 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
4 years ago

This plugin should resolve the issue https://wordpress.org/plugins/xml-sitemaps-manager/
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.


3 years ago

#5 @Cybr
3 years ago

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

#6 @westonruter
5 weeks ago

  • Milestone Awaiting Review7.1
  • Owner set to westonruter
  • Status newreviewing
  • Version5.5
Version 1, edited 5 weeks ago by westonruter (previous) (next) (diff)

#7 @westonruter
5 weeks ago

There is an internal error currently blocking this from being closed as a duplicate of #51117. However, once that bug is fixed, this can be closed as such.

Last edited 5 weeks ago by westonruter (previous) (diff)

#8 @westonruter
5 weeks ago

Actually, #51117 is not a duplicate. The home query is still running needlessly.

#9 @westonruter
5 weeks ago

  • Resolutionfixed
  • Status reviewingclosed

In 62664:

Sitemaps: Add the is_sitemap() conditional tag.

Introduce is_sitemap() as a conditional tag, mirroring the existing is_robots() and is_favicon() tags, and add the corresponding $is_sitemap property to WP_Query. The flag is set whenever the sitemap query variable is present, and a sitemap request is now excluded from being treated as the home page.

Developed in https://github.com/WordPress/wordpress-develop/pull/12142.
Follow-up to r47018, r48072.

Props masteradhoc, nimeshatxecurify, westonruter, mukesh27, madtownlems, ravanh, cybr, swissspidy.
See #51117.
Fixes #51542, #51543.

Note: See TracTickets for help on using tickets.