Steps to Remove Search Feature from WordPress Completely

Search feature in websites are really helpful for users to find and search for certain items in a website. WordPress comes with a default search feature. Although WordPress default search feature is not as bad as it was, it is still far from perfect. Searching in WordPress powered search does not always give you relevant results. This article shows steps to remove search feature from WordPress completely.

1. search field

Reasons to disable default WordPress search feature:

  • Search result shows unrelated links in the site search feature
  • For using third party site search site like Google Custom Search etc.
  • Default search is less likely to give visitors what they search for. This may scare them off.
  • If you have less amount of content in your website, search result may not be necessary.
  • Sticking with default search denies you search analytic.
  • If your competitors have better search on their sites, you can be left behind.

Steps to Remove Search Feature from WordPress Completely

You need to add a few lines of codes in the functions.php file to disable search feature completely from website. If you are wondering where to find functions.php file, follow these steps.

1. Login to your WordPress Dashboard.

2. Go to Appearance > Editor.

Steps to Remove Search Feature from WordPress Completely

3. The sidebar in the right has template files. Search for Theme Functions(functions.php) and select it.

Steps to Remove Search Feature from WordPress Completely

4. Copy and paste the following code in the functions.php file inside the php tag.

function 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', 'filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

5. Finally click the Update File button at the bottom to save it.

This code will remove the search function. In the above code if you set $error to be true, then the users will be directed to 404 page. If you set $error to be false, then the users stay at the same page where they tried to run the search.

Also Read:   How to Create a Visual Sitemap in WordPress
Remove Search Feature from WordPress using Plugin

If you don’t like above procedure, you can also use plugins like Disable search to perform the same task.

Step 1. Install and activate Disable Search

Go to Dashboard > Plugins > Add New and search for Disable Search in the search box.

Steps to Remove Search Feature from WordPress Completely

Step 2. Activate Plugin

Once you activate the plugin from Installed plugin list it should automatically disable search feature from your website. If you want to bring back the old default search field you can always delete the added code from the function.php file or disable the plugin.

 

The following two tabs change content below.
Kantiman Bajracharya

Kantiman Bajracharya

Kantiman Bajracharya is a freelance web developer. He is a computer geek who has a Bachelor’s degree in Computer Engineering. He has earned lots of satisfied customers while working for numerous successful projects. He is also a WordPress theme creator and web article writer. On free time he likes reading philosophy books, traveling and playing chess.

Share This Post