Noindex Selected Posts and Pages
Asks search engines not to index the posts and pages you list, such as thank-you, login or internal pages, while still following their links.
Opens WPIDE on
Code
// IDs of the posts and pages to keep out of search results.
$wpide_noindex_ids = array( 0 );
add_filter( 'wp_robots', function ( $robots ) use ( $wpide_noindex_ids ) {
if ( is_singular() && in_array( get_queried_object_id(), array_map( 'absint', $wpide_noindex_ids ), true ) ) {
$robots['noindex'] = true;
$robots['follow'] = true;
}
return $robots;
} );
Notes
Add the IDs to the list. Pair it with the sitemap exclusion snippet so the pages are not listed there either.
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.