Are you looking for a way to disable search feature in WordPress? Many times you may not need search feature because you have a simple business website or you are part of a growing community of the one-page websites or your theme settings doesn’t allow you to remove search feature.
We will show you how you can disable search feature completely from your website.
Look
You may be wondering why not just hide the search bar from theme settings or with CSS,
Well, the problem with that is, You can remove the search form in the design, but the functionality stays.
Anyone who knows you are using WordPress can simply add a /?s=keyword and search the site. But by removing the form and adding this code will take care of that problem. There will be a time when you have a client that only wants pages or posts to be shown if the URL is available. This function will come handy in those cases.
Let’s get started,
There are two ways you can remove the search bar from your site i.e, plugin and manual and we will show both ways and you decide which method you want to use.
Method 1. Disable Search Feature in WordPress Using a Plugin
This method is easier and is recommended for all beginners.
To begin with, plugin method you simply need to do install and activate the Disable Search plugin.
The plugin works out of the box, and there are no settings for you to configure.
After activation, it will remove search form from your WordPress theme and disable the search widget as well. If a visitor directly tried to enter a search query URL, the plugin will return a 404 error page.
Method 2. Remove Search Feature in WordPress with code Snippet
You just have to copy the below code in your theme’s functions.php file.which you can find from your
which you can find from your Wordpress Admin Dashboard > Appearance > Editor and find the file called functions.php or You can access the same via FTP.
Place the code at the very bottom of the file unless there is ?> sign at the end. If there is such sign than paste the code above “?>” sign.
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 simply redirect all search queries to a 404 page. It will also hide the search form in your WordPress theme or from widget area.
Reasons You should hide the search feature in WordPress
As mentioned above Many WordPress websites are simple business or portfolio websites with a few pages. There is also a growing trend of one-page websites with vertical navigation.
These websites do not have much content which makes a search form a knick-knack item and not a useful feature.
Another reason for disabling the search box that comes with WordPress is to replace with a different search box, such as Google Custom Search.
Google Custom Search allows you to monetize your search pages provides you have an Adsense account.
It also provides a tiny bit of extra layer of security where hackers(Spammers) use specific terms to find specific pages inside our sites.
We hope this article helped you learn how to easily disable search feature in WordPress. If you liked this article, then please follow us on Twitter and Facebook.