/* Disable Search Function in WordPress */
function wpflt_filter_query( $query, $error = true ) {
if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;
if ( $error == true )
$query->is_404 = true;
}}
add_action( 'parse_query', 'wpflt_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
This code will disable the search function in WordPress. There is a catch though.
Even if the search function is disabled, the user can still search for a keyword in the widget. But the page will return 404.
Make sure you remove the search Widget from direct access.
Now, a visitor can also search for a Keyword on your site by accessing the following URL, https://wpf.jaxn.in/?s=privacy. However, this page will also return 404.
Important 🙂
Most themes, have enabled the search box on the 404 page. Hence, you need to manually remove the search box from the respective theme’s 404 page. (Either add a custom 404 page or check in theme support forums on how to remove the search box)