WordPress search feature is really useful, but when we use WordPress as a CMS, sometimes the search feature becomes unnecessary. Well if you have been wanting to get rid of the search functionality, then this article will give perfect solution. In this article, we will Learn how to disable WordPress search feature in this quick guide.

Follow the given steps :

  1. First, go to your WordPress Dashboard and navigate to Appearance >> Editor
  2. Now open your theme’s functions.php file
  3. Add the following code to the file
function codecanal_filter_query( $query, $error = true ) {
	
    if ( is_search() ) {
        $query->is_search = false;
        $query->query_vars[s] = false;
        $query->query[s] = false;

        // to error
        if ( $error == true )
            $query->is_404 = true;
    }
}
add_action( 'parse_query', 'codecanal_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

Note: If you set $error = true, then the user will be redirected to your 404 page (theme’s 404.php must be exist). If you set it as false, then the user stays at the page where they tried to run the search.

There are currently no comments.