Do you want to learn to disable the search feature on your WordPress website?
The search feature is useful as it allows users on your site to search for a specific piece of information with ease.
But, for a simple business website or a growing one-page website that has limited content, the search feature is of no use. In such cases, removing the search option makes it clear for the audience that there is no other information to show.
Disable the Search Feature in WordPress
In this tutorial, we will learn to disable the search feature on a WordPress site. There are various ways to disable the feature in WordPress. In this tutorial, I have mentioned two different ways. Let’s Start:
Method 1: Remove/Disable the Search Feature using Plugin
In WordPress, there are thousands of plugin to limit the default function of the site. Here too, we can use a plugin to do so. Disable Search is one of the best plugins that allows you to remove this feature.
Install and Activate the Disable Search Plugin
As a first step, you need to have the Disable Search Plugin on your site. It’s a free WordPress plugin. Follow our tutorial guide on ‘How to Install a New WordPress Plugin?’ Activate the plugin after you install it.
Upon the activation of the plugin, the search feature will automatically be disabled from your site. No extra steps! It removes the search form on the site and disables the search widget.
Method 2: Manually Disable Search Feature using Code
The next method is by using a code. It’s simple. All you need to do is copy and paste the below-mentioned code in your theme’s function.php file. It is better to make use of the child theme as it gets easier to add code and doesn’t affect your site even if it’s placed wrong.
Code
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’ );
Wrapping Up
This is the end of the article. I hope this was helpful to remove/disable the search feature on your site. Also, follow our tutorials to learn more about WordPress!
Also, Check-Out: