wp_sitemaps_post_types
Allows you to specify the post types that should be included in the sitemap.
The analogous hook for taxonomies (categories) is wp_sitemaps_taxonomies.

Usage
add_filter( 'wp_sitemaps_post_types', 'wp_kama_sitemaps_post_types_filter' );
/**
* Function for `wp_sitemaps_post_types` filter-hook.
*
* @param WP_Post_Type[] $post_types Array of registered post type objects keyed by their name.
*
* @return WP_Post_Type[]
*/
function wp_kama_sitemaps_post_types_filter( $post_types ){
// filter...
return $post_types;
}
- $post_types(WP_Post_Type[])
An array of registered post type objects. The array keys contain post type names.
Array ( [post] => WP_Post_Type Object ( [name] => post [label] => Posts ... ), [page] => WP_Post_Type Object ( [name] => page [label] => Pages ... ), ... )
Examples
#1 Remove the note post type from the sitemap
# Disable sitemap generation for the `note` post type:
add_filter( 'wp_sitemaps_post_types', );
function( $post_types ){
unset( $post_types['note'] );
return $post_types;
}Changelog
| Since 5.5.0 | Introduced. |
Where the hook is called
wp_sitemaps_post_types
wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php 49
return apply_filters( 'wp_sitemaps_post_types', $post_types );