Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Turn off site search

Search results show the “not found” page, and search forms and Search blocks print nothing.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Tested with WordPress 7.1
PHP
<?php

add_action(
	'template_redirect',
	static function () {
		global $wp_query;
		if ( is_search() && ! is_admin() ) {
			$wp_query->set_404();
			status_header( 404 );
			nocache_headers();
		}
	},
	1
);
add_filter( 'get_search_form', '__return_empty_string', 99 );
add_filter( 'render_block_core/search', '__return_empty_string' );
add_action(
	'widgets_init',
	static function () {
		unregister_widget( 'WP_Widget_Search' );
	}
);

Good to know

This also turns off the WooCommerce product search. The editor’s link search keeps working.

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.