Tag Archives: CMS

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