Disable Site Search
Turns search off: search URLs return a 404 page, the search form is emptied and the classic Search widget is removed.
Opens WPIDE on
Code
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 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.