Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created March 29, 2023 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/870ae9f3392ab5b029fe12b4ed71fd2b to your computer and use it in GitHub Desktop.
Save damiencarbery/870ae9f3392ab5b029fe12b4ed71fd2b to your computer and use it in GitHub Desktop.
Sitemap - exclude a custom post type
<?php
/*
Plugin Name: Sitemap - exclude a custom post type
Plugin URI: https://wpza.net/how-to-exclude-post-types-from-wp-sitemap-xml-in-wordpress/
Description: Exclude a specific custom post type from the WordPress sitemaps.
Version: 0.1
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
*/
function dcwd_remove_cpt_from_wp_sitemap( $post_types ) {
unset( $post_types['cust_post_type'] );
return $post_types;
}
add_filter( 'wp_sitemaps_post_types', 'dcwd_remove_cpt_from_wp_sitemap' );
// Can also exclude specific posts: https://wpza.net/removing-specific-posts-from-wp-sitemap-xml-in-wordpress/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment