Disable search in WordPress

Here is a snippet to turn off the built-in search feature in WordPress. Can be useful if the site has little content and serves no function. functions.php

/* Disable search in WordPress - More snippets at wpunplugged.com  */ 

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

Share this post

Leave a Reply

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