Opened 4 years ago
Last modified 22 months ago
#51542 new defect (bug)
is_home() returns true for any component of an XML Sitemap
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Sitemaps | Keywords: | |
Focuses: | Cc: |
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 (5)
#2
@
3 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
@
3 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.
Possible duplicate of #51117