How to disable search in wordpress

Many websites do not have much content that they need a search bar. Search Bar also adds additional css and javascript to your site. If you want to keep your site minilastic & clean, the search box is unuseful for you.

Lets take a look at how to remove search bar from your search result.

The easy step to remove search from your site is edit your WordPress theme.

Solution 1 – Remove from Sidebar

If the search bar is present in the sidebar then, you have to go to the customization option of your theme.

Go to Widgets

remove for sidebar

Remove the “Search” Widget and Search bar will be removed from your sites Sidebar.

Solution 2 – Redirect to 404 Error page

If you have search box in header, footer or after post then you need to edit function.php file from the theme editor.

add the code given below to redirect any search query to 404 error page. With this method, you can prevent users to get search results.

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() {
add_action( 'widgets_init', 'remove_search_widget' );

Solution 3 – Remove from Header / Footer

In case, you also want to remove all search widgets from your site. Then, first you have to find where is your search widget. If your Search Icon is in the header/navigation menu then edit your header.php and if the search box is in footer, edit footer.php.

Note – The next step is little complicated and can also brake your theme. So, i suggest you to take backup of full theme or page that you are editing.

remove search box from header or footer

Remove the code mentioned as above to remove search box from respective position.

Solution 4

This method is very easy. You just have to add a plugin called “Disable Search“.

disable search plugin

This plugin do not need any configuration. Just install it and it will remove all the search boxes and icons from your WordPress theme. And if any user tried to search from url parameters then it will rediret to the 404 error page.

This method is very easy and step forward. But, it will also a plugin into your theme which you may not like much that’s why we kept this method at last position.