# Keep REST API Responses Out of Search Results

> Sends an X-Robots-Tag: noindex header with every REST API response so search engines do not index raw JSON from /wp-json/ next to your real pages.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: rest-api, seo, headers
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/rest-noindex-header/

## Code

```php
add_filter( 'rest_post_dispatch', function ( $response ) {
    if ( $response instanceof WP_REST_Response ) {
        $response->header( 'X-Robots-Tag', 'noindex, nofollow' );
    }

    return $response;
} );
```

## Notes

This does not block access to the API; it only asks search engines not to index the responses.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Keep REST API Responses Out of Search Results" 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/
