How to Disable WordPress Search Feature

Pradeep SinghLast Updated:

How to Disable WordPress Search Feature

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.

Disable Search WordPress Plugin Download

Follow these steps to disable the WordPress search feature with a popular Disable Search plugin.

  1. From your WordPress dashboard, go to Plugins > Add New and search for Disable Search plugin.
  2. Install and activate the Disable Search plugin from the WordPress plugin repository.
  3. 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.

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.

About the author

Pradeep Singh

Pradeep Singh is the founder and your host here at WPism. He is an entrepreneur and blogger living his startup life based in London and Cambridge. Connect with him on LinkedIn, follow him on Twitter or like his page on Facebook.