WordPress:
WordPress is a blogging software tool as well as a framework for web development. It is an open source software written in PHP and MySQL. It helps the users to create websites quickly and easily. WordPress was released on May 27, 2003, by founders Matt Mullenweg and Mike Little.
Why Should Disable Search Feature in WordPress?
Mostly all the WordPress websites are simple with few pages. These websites do not have much content so search form will not be a useful feature. Removing search option will clean up your website and gives a better user experience. To disable the search option in WordPress, follow the below methods:
Method 1: Using a WordPress Plugin
WordPress provides a plugin named” Disable Search” that removes search form appearing in most WordPress themes and disables the search widget from your website. Follow the below steps to do disable the search option from your website.
Step 1: Login into the WordPress admin dashboard with valid credentials.
Step 2: Navigate to Plugins option and click ‘Add New’ to install the new plugin.
Step 3: Go to the search option and enter ” Disable Search“, then install and activate it.
Once activated the plugin will disable the search feature immediately and no extra settings need to be configured. If you want to reinstate the search feature, just deactivate the plugin. This is one of the easiest methods to disable the search feature through the plugin.
Method 2: Disabling Manually Using Code
For this method, you will need to add the below code in your functions.php file. Click open the mentioned file through File Manager in cPanel and edit it with the below code. This code will hide the search form in your WordPress theme and also redirects all search queries to a 404 page.
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' );
We hope that this tutorial will help you to Disable the search option from your WordPress website. For more information, follow us on Twitter and Facebook and For video tutorials, subscribe to our YouTube channel ServerCake India.