How to Disable Search Feature in WordPress Easily

Search Feature is indeed one of the most useful features to have on websites of any kind. However, sometimes, your website might not need the search feature or the search form in your theme might interfere with the user experience. So, for times like that, you might want to disable search feature on your website. And to do just that, we have come up with two methods: disable search feature by using a plugin and manually.

Many business websites are built with very few pages and the search feature does not seem to be quite useful for these kinds of websites. Also, the search feature on these websites makes users think that there might be some other information that they can’t see. Therefore, in these situations, disabling the search feature will clean up your website and offer a better user experience. So, without any further ado, let’s get started.


Disable Search Feature in WordPress Using a Plugin 


The first step is to install and activate the Disable Search plugin from the WordPress Plugin Directory. The plugin only affects search on the front-end of the site. But, does not disable searching in the admin section of the site.

The plugin, once activated, will work on its own. You will not be provided with any configuration options.

After activating the plugin, it will remove the search feature from your WordPress theme and disable the search widget as well. If a user directly tried to enter a search query URL, the plugin will return a 404 error page.

before and after the pluign is activated

However, you’ll still be able to search posts and pages inside your WordPress admin area.


Disable Search Feature in WordPress Manually 


Disabling search feature in WordPress manually requires you to add code to your WordPress files. So, if you don’t want to mess around with coding, we suggest you go for the first method.

All you have to do is copy the following codes and paste it into your theme’s functions.php file or a site-specific plugin.

 function wpb_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', 'wpb_filter_query' ); 
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
function remove_search_widget() {
unregister_widget('WP_WIdget_Search');

add_action( 'widgets_init', 'remove_search_widget' ); 

The code will redirect all direct and indirect search queries to a 404 page and it will also hide the search feature in your WordPress theme.

And that’s all there is. We hope this article helped you to disable search feature in WordPress. As we mentioned earlier, if you are a beginner, not familiar with coding or just don’t want to mess around with code, then we recommend you to use the first method, i.e. via a WordPress plugin.

If you have anything to add, ask or share, please feel free to use the comments section below.

 

Reference: WP Beginner

1 thought on “How to Disable Search Feature in WordPress Easily”

Leave a Reply

Your email address will not be published. Required fields are marked *