
This snippet disables the default WordPress search results page. When someone visits a search URL like /?s=keyword, they’ll be sent to the 404 page instead.
Place the PHP snippet in your theme’s functions.php file or add it using a code snippets plugin to enable the logic.
add_action('template_redirect', function () {
if (is_search() && !is_admin()) {
global $wp_query;
$wp_query->set_404();
status_header(404);
nocache_headers();
return;
}
});Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.