Monday, December 1, 2014

How to Disable the Search Feature in WordPress

WordPress has by default built-in search feature, which allows you to search the content within your WordPress website. If you are using WordPress as CMS, then you may want to get rid of the search feature.

We can easily do this by adding the following code in functions.php file, which is located in theme directory.
//Disable WordPress Search Feature

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

0 comments:

Post a Comment