Turn off site search
Search results show the “not found” page, and search forms and Search blocks print nothing.
<?php
add_action(
'template_redirect',
static function () {
global $wp_query;
if ( is_search() && ! is_admin() ) {
$wp_query->set_404();
status_header( 404 );
nocache_headers();
}
},
1
);
add_filter( 'get_search_form', '__return_empty_string', 99 );
add_filter( 'render_block_core/search', '__return_empty_string' );
add_action(
'widgets_init',
static function () {
unregister_widget( 'WP_Widget_Search' );
}
);
Good to know
This also turns off the WooCommerce product search. The editor’s link search keeps working.
In these packs
- Turn off what you don’t use: Each of these replaces a small plugin: no comments, classic editor, no feeds, no search and more.