How to disable Search on your WordPress site and why?

 

In some situations, the search string on the site may be superfluous or inappropriate. Even worse, if the search string hinders the visitor when navigating the site and disrupts the integrity of the user interface.

In this little lesson, we’ll show you how to turn off the search function and the search bar on the WordPress site, and explain in which situations this helps.

Why should I disable Search on the WordPress site?

A lot of corporate sites use WordPress for their landings and information pages. Also, the so-called single-page sites with vertical navigation are gaining popularity.

On sites where the content is static and not updated regularly, the site search will in most cases be superfluous.

The search helps only on sites where materials are updated and published regularly, for example, on our blog.

Also, the search string on sites with static content can be misleading, because the visitor will think that there is a lot of other additional information on the site that is hidden somewhere in the bowels of the site.

In such cases, it would be advisable to disable the search altogether, in order not to confuse the visitor and not to spoil the user interface.

Method 1. Disable Search

The easiest way to disable search on WordPress is a free plugin Disable Search :

The plugin works right out of the box, just install and activate it. There’s nothing to adjust.

Right after activation, the plugin will automatically remove the search string from your site and disable the widget with the search.

If a visitor is persistent and enters a search query directly in the browser line, he will simply go to the 404 page:

Please note that this plugin removes the search only on the site itself. Inside the admin area, you, as before, will be able to use the search and search for your records and pages.

Method 2. Disable the search manually

This method is a little more complicated, and we do not recommend it for beginners.

You need to open the file functions.php of your active WordPress theme and add the following code to it:

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

This code will hide the search form for your skin. It will also redirect all direct and indirect search queries to the standard 404 page.

Before / After

That’s it! It was very simple, right? We showed 2 simple ways how to remove the search and the search form from your WordPress site.

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*