Noindex an Entire Post Type
Keeps every entry and the archive of chosen post types out of search results and removes them from the built-in XML sitemap, while visitors can still open them.
Opens WPIDE on
Code
// Post types to keep out of search engines.
$wpide_noindex_types = array( 'testimonial', 'partner' );
add_filter( 'wp_robots', function ( $robots ) use ( $wpide_noindex_types ) {
if ( is_singular( $wpide_noindex_types ) || is_post_type_archive( $wpide_noindex_types ) ) {
$robots['noindex'] = true;
$robots['follow'] = true;
}
return $robots;
} );
add_filter( 'wp_sitemaps_post_types', function ( $post_types ) use ( $wpide_noindex_types ) {
return array_diff_key( $post_types, array_flip( $wpide_noindex_types ) );
} );
Notes
Useful for thank-you pages, internal resources or thin listings. SEO plugins have their own per-type setting.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.