SocilerWordpress Wordpress TutorialsDisable the Search Feature of WordPress

Disable the Search Feature of WordPress

Disable WordPress Search Recently in one of my blogs, I didn’t want the default search of the WordPress and wanted to remove it. Intrestingly WPEngineer had a solution by adding some code. Well, it was easy to do that and if you too wanted to remove the default search code for wordpress search here’s how to do it.

1. First go to your WordPress Dashboard and navigate to Appearance >> Editor

2. Now open your theme’s functions.php file.

3. Add the Following code to the file.

    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;" ) );

Please note that if you set $error to be true in the above code, then the user will be redirected to your 404 page. So you must have your theme’s 404.php . If you set it as false, then the user stays at the page where they tried to run the search.
Let us know if have disable the wordpress search in your blog through any other options.

One comment

  1. Pingback: Getting custom post types out of wordpress searches

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>