# Disable Site Search

> Turns search off: search URLs return a 404 page, the search form is emptied and the classic Search widget is removed.

- Type: PHP
- Runs: Run everywhere
- Category: [Disable Features](https://wpide.com/library/category/disable-features/)
- Tags: search, disable
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/disable-site-search/

## Code

```php
add_action( 'template_redirect', function () {
    global $wp_query;

    if ( is_search() && ! is_admin() ) {
        $wp_query->set_404();
        status_header( 404 );
        nocache_headers();
    }
} );

add_filter( 'get_search_form', '__return_empty_string', 999 );

add_action( 'widgets_init', function () {
    unregister_widget( 'WP_Widget_Search' );
}, 11 );
```

## Notes

Search blocks placed in block themes still render; remove them from your templates.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Disable Site Search" 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/
