How to disable the search feature in WordPress

By Default, WordPress comes with a built-in search feature which allows you to search the content within your WordPress website. However, if you are using WordPress as a content management system, you may want to get rid of the search feature,

You can easily do that by adding following code in your functions.php file located inside your 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;" ) );

See Also: How to Remove Website URL Field from Comment Form

0 Comments

Leave a Comment.