Wednesday 11 October 2017

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. In this article, we will show you how to easily disable the search feature in WordPress.

Disabling 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. For more details, see our step by step guide on how to install a WordPress plugin.

The plugin works out of the box, and there are no settings for you to configure.

Upon 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. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

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.

Search form widget removed

We hope this article helped you learn how to easily disable search feature in WordPress. You may also want to see our mega list of the most wanted WordPress tips, tricks, and hacks.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Disable the Search Feature in WordPress appeared first on WPBeginner.



source http://www.wpbeginner.com/wp-tutorials/how-to-disable-the-search-feature-in-wordpress/

No comments:

Post a Comment