Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#54887 closed enhancement (invalid)

Enhancement when filter returns an empty url

Reported by: kybernetikservices's profile kybernetikservices Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.8.3
Component: Sitemaps Keywords:
Focuses: Cc:


Hi guys.

I'm the author of the plugin WP Sitemaps Config One of the features is to explude pages and posts from the sitemap. To achieve this I use the filter wp_sitemaps_posts_entry
The apply_filters() function is located in class-wp-sitemaps-posts.php at line 140.

When a user decides to explude a page or post, I do return array( 'loc' => '' ) for this url. Unfortunatley this produces an empty line with <url><loc/></url> in the sitemap.
Google gives an error when reading this sitemap.

Sitemap can be read, but has errors
Invalid URL

To prevent this, the code in class-wp-sitemaps-posts.php at line 141 should be changed in

if( !empty( $sitemap_entry[ 'loc' ] ) ) {
  $url_list[]    = $sitemap_entry;

This would prevent a blank line if the URL is removed by the filter.

Change History (3)

#1 follow-up: @swissspidy
2 years ago

This filter is not meant for removing URLs.

You should modify the query args to do so, see

#2 in reply to: ↑ 1 @kybernetikservices
2 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Thank you so much @swissspidy for your time and reply.
I will take this into account and modify my code.

#3 @peterwilsoncc
2 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.