Make WordPress Core

Opened 6 years ago

Closed 5 weeks ago

Last modified 5 weeks ago

#51543 closed feature request (fixed)

Create is_sitemap() conditional tag

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

Description

As people continue expanding and customizing Core's XML sitemaps, I believe an is_sitemap() conditional tag would be very helpful.

In the short term, its existence would be very useful for getting around the bug explained in #51542 (https://core.trac.wordpress.org/ticket/51542), but surely developers will find other ways to make use of it and it seems like a natural fit to be a conditional tag.

Change History (11)

#1 @RavanH
4 years ago

The is_sitemap() conditional is now provided by https://wordpress.org/plugins/xml-sitemaps-manager/ :)

This ticket was mentioned in PR #12142 on WordPress/wordpress-develop by @masteradhoc.


2 months ago
#2

  • Keywords has-patch added

This patch introduces is_sitemap() as a conditional query tag and adds the $is_sitemap property to WP_Query, following the established pattern of is_robots() and is_favicon().

Trac ticket: https://core.trac.wordpress.org/ticket/51543

## Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): Claude Sonnet 4.6
Used for: Initial implementation scaffolding. All code was reviewed, adjusted, and tested by me.

@masteradhoc commented on PR #12142:


2 months ago
#3

@mukeshpanchal27 to make reviewing easier i split the second trac ticket to a own PR, see: https://github.com/WordPress/wordpress-develop/pull/12150

#4 @masteradhoc
2 months ago

  • Milestone Awaiting Review7.1

@westonruter commented on PR #12142:


2 months ago
#5

✅ New code passes PHPStan rule level 10 with the bleeding edge ruleset.

#6 @westonruter
2 months ago

  • Owner set to westonruter
  • Status newreviewing

@masteradhoc commented on PR #12142:


2 months ago
#7

@westonruter thanks to @nimesh-xecurify we have now tests as well for this PR :)

#8 @mukesh27
5 weeks ago

  • Keywords commit added

@westonruter This one is ready for commit

#9 @westonruter
5 weeks ago

  • Version5.5

#10 @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.

#11 @westonruter
5 weeks ago

Note: The is_sitemap() function does not return true for sitemap stylesheet requests, e.g. /wp-sitemap-index.xsl.

This XSL stylesheet is referenced in the sitemap XML:

<?xml-stylesheet type="text/xsl" href="http://localhost:8000/wp-sitemap-index.xsl" ?>

I think we should remove the sitemap stylesheet from core, however.

Chrome is deprecating and removing XSLT, and other browsers are doing the same.

Note: See TracTickets for help on using tickets.