[wp-trac] [WordPress Trac] #54887: Enhancement when filter returns an empty url
WordPress Trac
noreply at wordpress.org
Sun Jan 23 16:09:00 UTC 2022
#54887: Enhancement when filter returns an empty url
--------------------------------+-----------------------------
Reporter: kybernetikservices | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Sitemaps | Version: 5.8.3
Severity: normal | Keywords:
Focuses: |
--------------------------------+-----------------------------
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
{{{#!php
if( !empty( $sitemap_entry[ 'loc' ] ) ) {
$url_list[] = $sitemap_entry;
}
}}}
This would prevent a blank line if the URL is removed by the filter.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54887>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list