Learn how to disable the WordPress search feature in this quick guide.
The WordPress search feature is really useful, but you might easily come across a situation where you want to remove the default search feature.
Recently one of our clients asked us to remove the default search of WordPress from their front end. As I started to explore options, I was surprised to see so many other users looking to do this.
If you, too, want to remove the default search code for WordPress search, here’s how to do it.
Steps to Disable WordPress Search With Plugin
We will make use of the popular disable WordPress search plugin available to download for free from the WordPress repository.
Follow these steps to disable the WordPress search feature with a popular Disable Search plugin.
- From your WordPress dashboard, go to Plugins > Add New and search for Disable Search plugin.
- Install and activate the Disable Search plugin from the WordPress plugin repository.
- Once activated, the plugin should disable the built-in front-end search capabilities of your WordPress blog.
It’s important to note that the plugin only disables search on the front end of your WordPress website. If you still see search boxes, it might be because of the theme you are using.
This plugin will, however, ensure that the search function from those boxes is disabled.
Editing Code to Disable WordPress Search
As I continued to look for manual options, I found that WPEngineer had a solution by adding a few lines of code.
Follow these steps only if you are comfortable editing your WordPress theme files. This is not recommended for WordPress beginners.
- First, go to your WordPress Dashboard and navigate to Appearance >> Editor
- Now open your theme’s functions.php file.
- Add the following code to the file.
function fb_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', 'fb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
https://gist.github.com/pradeepdotco/646410736ee5f1d7c7f7
Please note that if you set $error
to be true in the above code, then the user will be redirected to your 404 page.
So you must have your theme’s 404.php. If you set it as false, then the user stays at the page where they tried to run the search.
Have you disabled the search feature in your blog? Let me know in the comments below.
In my primary domain I had one WP installation for the blog, but I needed also a section for landing/squeeze/thanks pages, and I wanted these pages not to be easily discoverable. So, I opted for a second WP installation with all the flags and whistles off (pingback/trackback, update service, feeds, search results). Thanks to your article I put together the final piece of the puzzle – search results. Thank you. 🙂
Using your code changed the look of my site. Can you please help? I have no idea where exactly the code should go to work properly.
Hi Sam,
The code should go in the functions.php of your theme (preferably child theme).
If you are not comfortable with code, please use the plugin mentioned above.
thanks bro, ur tips helped