Free Wordpress Blog Setup

How to Disable the Search Feature in WordPress

By Editorial Staff in Tutorials
How to Disable the Search Feature in WordPress

When using WordPress as a CMS, sometimes the search feature becomes unnecessary. Well if you have been wanting to get rid of the search functionality, then this article is just for you. In this article, we will show you how to disable the search feature in WordPress.

Open your theme’s functions.php file and add the following codes:

function fb_filter_query( $query, $error = true ) {

if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;

// to error
if ( $error == true )
$query->is_404 = true;
}
}

add_action( 'parse_query', 'fb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

Note: if you set $error to be true, then the user will be redirected to your 404 page (theme’s 404.php must exist). If you set it as false, then the user stays at the page where they tried to run the search.

Source: WPEngineer

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

5 Responses to “How to Disable the Search Feature in WordPress”
  1. Marc T says:

    Hmmmm…. can’t imaging Search not being important for a CMS. Isn’t the fact that WordPress has such a fine Search feature a huge advantage when using it as a CMS? I can imaging Search only being not important on a small portfolio site say limited to 5 pages or so.

  2. I’m having a hard time understanding the usefulness of this code. If search is unnecessary wouldn’t it make more sense to not include the search form? If you leave a search form on a page and then don’t let someone use that search form isn’t that very poor usability?

    Am I missing something?

    • You can remove the search form in the design, but the functionality stays. Anyone who knows it is 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 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 that sense.

  3. W3Mag says:

    Heh! Thanks for the tips I was looking to do this at one moment and had no clue on how I can do it!

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar