Manually Disable the Default Search Bar in WordPress

WordPress has a default search feature that appears in all the pages. A search feature is a great tool that helps visitors navigate easily to their destination. However, below are some reasons that may require you to disable the search bar.

Reasons for disabling the search feature in WordPress

1. Landing Page. A landing page is a minimal website meant to entice new visitors into making a quick sale. These pages require to be minimalistic as possible and most do not need a search bar.

2. One-page website. One-page websites have been on trend recently especially among small businesses. These kinds of websites usually do not have much content to show, therefore, a search bar is irrelevant.

3. It is proven that most website attacks are performed via the search text box. They input malicious queries that result in compromised data.

To follow along with this step by step tutorial, you will need access to your website files and folders. Either FTP or Cpanel can achieve this. You will learn how to disable the search feature in WordPress using the Cpanel manually.

you need Cpanel login credentials that can be provided by your web hosting company.

Login into your Cpanel and locate the file manager. Open the file manager.

On the left, open the ‘public_html’ folder to access your website files.

Open the ‘wp-content’ folder.

Open the themes folder.

Locate the folder of the active theme. In the demonstration below, the active theme is ‘twentyseventeen’.

Find the ‘functions.php’ file. The files are arranged alphabetically so it should be easy to find it.

Select the ‘functions.php’ file then click on the ‘edit’ button at the top of the page.

When the pop-up appears as shown below, select the ‘edit’ button to proceed to the editor.

Copy and paste the code below at the bottom then click on the ‘Save Changes’ button.

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' );

If you have followed all the steps in this tutorial, you will realize that the search bar is no longer there as shown below.

You May Also Like

About the Author: Abdelrahman Reda

Abdelrahman Reda is a Motivated Support Engineer with 6+ years of corporate and consumer support experience. His experience related to administration of Network, NOC support, computers and anti-virus server, data entry, networking sites, remote support.

Leave a Reply

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