Disable WordPress Search

Not always is the search in WordPress desired. The one or another application with WordPress doesn’t need this feature. Even if it is an added value in my opinion. In some cases, it still shouldn’t be displayed and so I have them deactivated with access to two hooks. For now, I can see no other place where you could access it in my applications and it works so smoothly.

The second call of the Hook get_search_form is just to take out the search from the frontend, so you should start the two hooks only if you are not in the admin: if ( !is_admin() ) .

If you set the variable $error to true, then you will be fowarded to the error page of the theme, if not, then you will remain on the page from where the search was started.

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

Additions, improvements or criticism – let us know! The comment field is as always open, and the solution is delighted when it will be refined.


6 responses to “Disable WordPress Search”

  1. […] Möglichkeit die Suchfunktion von WordPress zu deaktivieren stellt Frank auf deutsch und englisch vor. Funktioniert einwandfrei und ist mit Franks Anleitungen einfach zu […]

  2. kbhuffaker Avatar

    I would like to try and use your code to disable my search bar on certain tabs. I’m really new to wordpress and all the code it contains. Please advise me where to place your function and where to place the function calls. My search is in the sidebar1.


  3. Michael Avatar

    kbhuffaker: Copy the code in the functions.php for your active theme. Than remove the searchform from your sidebar. Thats all.

  4. kbhuffaker Avatar

    Thanks Michael. Now here is another rookie question. Where would I add the add_action and add_filter function if I didn’t want the search option to show in say my About_Me page?

  5. david Avatar

    hi, I use search everything plugin but I’m in need to disable the search on the content, I only want to run it on titles and user metas, Any idea how to implement such a thing?