Leave individual posts or pages, such as a thank-you page or a landing page for ads, out of the WordPress sitemap.
add_filter( 'wp_sitemaps_posts_query_args', function ( array $args, string $post_type ): array {
// IDs of posts and pages to leave out.
$exclude = [ 42, 108 ];
$args['post__not_in'] = array_merge( $args['post__not_in'] ?? [], $exclude );
return $args;
}, 10, 2 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Thank-you pages, ad landing pages and members-only pages don’t belong in your sitemap. This snippet leaves them out by ID.
WordPress builds each post type’s sitemap with a database query. The wp_sitemaps_posts_query_args filter lets you change that query; adding IDs to post__not_in leaves those posts out, whatever their type.
post.php?post=42), or use the snippet that shows IDs in admin lists.Open the page sitemap at /wp-sitemap-posts-page-1.xml. The excluded page shouldn’t be listed.