#54887 closed enhancement (invalid)
Enhancement when filter returns an empty url
Reported by: | kybernetikservices | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.8.3 |
Component: | Sitemaps | Keywords: | |
Focuses: | Cc: |
Description
Hi guys.
I'm the author of the plugin WP Sitemaps Config https://wordpress.org/plugins/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)
Note: See
TracTickets for help on using
tickets.
This filter is not meant for removing URLs.
You should modify the query args to do so, see https://make.wordpress.org/core/2020/07/22/new-xml-sitemaps-functionality-in-wordpress-5-5/