0

Instead of no indexing a page I just want to exclude it from the auto created wp-sitemap.xml

(some code in the functions.php file)

I found this but it did not seem to work?

https://perishablepress.com/customize-wordpress-sitemaps/#exclude-pages

Anyone shed some light....

Please no Yoast info!!!

0

The code below does work, just make sure you are editing the correct themes function.php file!

// Remove specific pages
function gt_disable_sitemap_specific_page($args, $post_type) {
if ('page' !== $post_type) return $args;
$args['post__not_in'] = isset($args['post__not_in']) ? $args['post__not_in'] : array();
$args['post__not_in'][] = 221; //locations
$args['post__not_in'][] = 261; //blog
return $args;
}
add_filter('wp_sitemaps_posts_query_args', 'gt_disable_sitemap_specific_page', 10, 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.