# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: noindex, robots, pages
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/noindex-selected-pages/

## Code

```php
// 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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Noindex Selected Posts and Pages" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
