How To Disable The Search Feature In WordPress

WordPress comes bundled with tons of built-in features one of which is Search. As the name suggests it lets you search through the contents of your WordPress website. However, if for some reason you want to disable this feature you can easily do that using a tiny code snippet.
 
All you need to do is copy the following code snippet and paste it inside functions.php file located inside the root of your active theme folder.
  1. function csc_disable_filter_query( $query$error = true ) {  
  2.   if ( is_search() ) {  
  3.     $query->is_search = false;  
  4.     $query->query_vars[s] = false;  
  5.     $query->query[s] = false;  
  6.     if ( $error == true )  
  7.       $query->is_404 = true;  
  8.   }  
  9. }  
  10. add_action( 'parse_query''csc_disable_filter_query' );  
  11. add_filter( 'get_search_form', create_function( '$a'"return null;" ) );  
The above code snippet will redirect any search query performed by the user to a 404 page.
 
Also, you can place following code snippet into your functions.php file to disable Search widget from your WordPress website.
  1. function csc_disable_search_widget() {  
  2.     unregister_widget('WP_Widget_Search');  
  3. }  
  4. add_action( 'widgets_init''csc_disable_search_widget' );