Source file: modules/sitemaps/sitemap-builder.php
View in GitHubParameters
- $skip
-
(bool) Current boolean. False by default, so no post is skipped.
- $post
-
(object) Current post in the form of a $wpdb result object. Not WP_Post.
Changelog
Since: Jetpack 3.9.0
Notes
You can use this filter to remove specific posts from your sitemap, like so:
function jetpackcom_sitemap_exclude_post( $skip, $post ) { if ( 2146 == intval( $post->ID ) ) { $skip = true; } return $skip; } add_filter( 'jetpack_sitemap_skip_post', 'jetpackcom_sitemap_exclude_post', 10, 2 );
Why is $skip set to false if the post does not match? This means that only the final instance of this snippet will have any effect – all the previous instances will be overridden.
Additionally, I am not sure why the post ID here is a string, when it’s an integer in WP_Post.
Thanks for the feedback! I updated the snippet accordingly.
How should this filter code be used? Where should it be placed?
You can see an example of how to use this filter in the Notes section above. If you’re having trouble adding the code to your site, try using a Code Functionality plugin, like this.
Can I skip multiple pages with the one piece of code? If so, how do I add 3 pages to be removed from the sitemap? My cart, checkout and accounts pages are marked noindex but Jetpack still lists them in the sitemap, so Google Console keeps finding them. Their IDs are 28, 29 and 30. Thank you.
Hi there!
You can try this code, which should exclude multiple pages from your sitemap:
https://pastebin.com/raw/ZRf7G8Q1
Note that I haven’t tested this myself, but it’s only a simple variation on the existing code.
Also, where do I place this snippet within the sitemap-builder.php file, e.g. at the top, bottom or before some other specific command?
You should not directly modify any plugins files, ever. You can add code snippets to your site using a plugin like this one:
https://wordpress.org/plugins/code-snippets/
Can someone tell me why this snippet is not working?
I’m using a Snippets plugin.
I tested that snippet on my own site, and it seems to work fine. (Though of course I had to adjust the post ID to match a post of my own.) If you’re still having trouble, can you contact us here?
https://jetpack.com/contact-support/
Thanks!
I created a ticket, thank you Adam.