Disable the WordPress Public Search

Sometimes you just might not need the search functionality for your website but, just by not enabling it doesn’t mean the content is not searchable, If for any reason you need to disable the WordPress public search use this function.

function my_disable_public_search( $q ) {
	if ( $q->is_admin ) {
		return $q;
	}

	if ( $q->is_search ) {
		unset( $_GET['s'] );
		unset( $_POST['s'] );
		unset( $_REQUEST['s'] );
		$q->set( 's', '' );
		$q->is_search = false;
		$q->set_404();
	}
}

add_action( 'parse_query', 'my_disable_public_search', 5 );

About

Founder of Delicious Brains, the company behind the WP Migrate DB Pro plugin.

2 thoughts on “Disable the WordPress Public Search

Leave a Reply

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