How to Disable the Search Feature in WordPress

Do you want to disable the search feature in WordPress? Sometimes your site may not need the search feature and the search form in your theme may interfere with user experience. During this article, it has been clearly expressed that how to easily disable the search feature in WordPress.


Why and Who Should Disable Search Feature in WordPress?

Many WordPress websites are simple business websites with a few pages. There is also a growing trend of one-page websites with vertical navigation.

These websites does not have much content which makes search form a novelty item and not a useful feature.

It also gives users the impression that there might be some other information that they can't see and hence the search option. Removing search feature will clean up your website and offer a better user experience.

That being said, let's take a look at how to easily remove search feature from your WordPress site.

Method 1. Remove Search Feature in WordPress Using a Plugin

This method is easier and is recommended for all users.

First thing you need to do is 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. If a user directly tried to enter a search query URL, the plugin will return a 404 error page.

Note that this plugin does not affect the search functionality inside the WordPress admin area. You can still search posts and pages inside your WordPress admin.

Method 2. Manually Disable Search Feature in WordPress

This method requires you to add code to your WordPress files.

You will need to add this code to your theme's functions.php file or a site-specific plugin.


 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 direct or indirect search queries to a 404 page. It will also hide the search form in your WordPress theme.

I hope this article helped you learn how to easily disable search feature in WordPress.

No comments:

Post a Comment

PHP Tutorial

PHP is the most popular server-side scriptiong language for creating dynamic web pages. PHP stands for Hypertext Preprocessor. PHP is a ver...