'disable_search', 'title' => 'Disable frontend search', 'desc' => 'Remove search form and redirect /?s= queries', 'icon' => 'search', 'risk' => 'risky', 'level' => 'advanced', 'audience' => 'business', 'priority' => 9, 'benefit' => 'Search results pages are usually not cached, so a large number of search requests can put load on your database. If your site does not need search, this avoids those queries.', 'help' => 'For brochure and landing-page sites that do not need search. Search requests (/?s=...) get a 301 redirect to the homepage, and search forms printed through get_search_form() are removed. A Search block added in the block editor still shows, but its results redirect too. When WooCommerce is active, product search keeps working.', 'before' => '/?s=anything shows search results', 'after' => 'Searches redirect to the homepage; WooCommerce product search still works.', 'detect' => function () { if ( class_exists( 'WooCommerce' ) ) { return array( 'detected' => true, 'message' => 'Search is enabled. WooCommerce product search will be preserved; only non-product search is disabled.', 'safe' => false, 'savings' => 'Security', ); } return array( 'detected' => true, 'message' => 'Search is enabled on this site', 'safe' => false, 'savings' => 'Security', ); }, 'callback' => function () { add_action( 'template_redirect', function () { if ( ! is_search() ) { return; } // Preserve WooCommerce product search (/?s=foo&post_type=product) // — it's a core storefront feature, not a DDoS vector like the // unrestricted generic search this feature guards against. if ( class_exists( 'WooCommerce' ) && 'product' === get_query_var( 'post_type' ) ) { return; } wp_safe_redirect( home_url(), 301 ); exit; } ); add_filter( 'get_search_form', function () { return ''; } ); }, );