Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Disable the Search Feature in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
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

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. tina alfieri says:


    I want to remove the search box completely on my home page. How do I do this please?

  2. Tati says:

    Odd… I’ve sent a message and looks like it didnt was aproved. Now the site sends me message about new comments in this thread, but nothing new here. Nice work. I’m flagging as a spam.

  3. Tati says:

    Thanks for the article. What I need to know is: can I disable only some terms of the search and keep the search function working? I want to exclude things like /?s=d, download, thank, success, congratultions… terms that hackers use to find specific pages inside our sites.

    Can someone help me with this? TIA

    • WPBeginner Support says:

      Please take a look SearchWP plugin. It allows you to improve WordPress search. Among its many features it also allows you to exclude terms.

  4. Silvana Donato says:

    Thank you very much.
    I have just been hacked in the database of one of my websites and I have removed all the possible gates to these terrible annoying people, who have nothing to do in life but distroying other people work.
    So I removed the search forms but i did not know how to remove the query string.

  5. Gary C says:

    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.

  6. jvquarck says:

    adding an if at the beginning checking if you are in the admin, may help not screwing up the admin searching functions:

    if ( !is_admin() )

    all the query-> assignments here !!


  7. George Stephanis says:

    Erm … there’s no need to use create_function … WordPress already has placeholder functions for all the simple return values. So instead of doing

    add_filter( ‘get_search_form’, create_function( ‘$a’, “return null;” ) );

    you can just do

    add_filter( ‘get_search_form’, ‘__return_null’ );

  8. 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!

  9. Steven Bradley says:

    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?

    • Editorial Staff says:

      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.

  10. 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.

    • Editorial Staff says:

      There are times when you are using WordPress to create a standalone site for a client where you only want people to know about the pages if they have the URL.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.