WP 5.5 XML Sitemap Exclude Page(s)

I’m using the information on this page about the new XML Sitemaps functionality in WordPress 5.5 to try to exclude two pages from the sitemap.

The example for excluding posts includes this sample code:


add_filter(
    'wp_sitemaps_posts_query_args',
    function( $args, $post_type ) {
        if ( 'post' !== $post_type ) {
            return $args;
        }
 
        $args['post__not_in'] = isset( $args['post__not_in'] ) ? $args['post__not_in'] : array();
        $args['post__not_in'][] = 123; // 123 is the ID of the post to exclude.
        return $args;
    },
    10,
    2
);

Since I want to exclude two pages, not a post, I have changed the post_type to “page” and added the two page IDs to the $args array:


add_filter(
    'wp_sitemaps_posts_query_args',
    function( $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'][] = 82;
        $args['post__not_in'][] = 86;
        return $args;
    },
    10,
    2
);

I added the code to my child theme’s functions.php, but the two pages still show up in the sitemap. I thought maybe the double underscores after “post” were a typo, so I tried single underscores, but that didn’t work, either. I haven’t been able to find any other documentation on excluding pages. Does anyone know what I’m doing wrong?



Source link