Utilities & Scripts
Disable Search Archive Page

Info

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.

Utilities & Scripts
April 29, 2026

Setup

00

Add Custom PHP

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;
    }
});
00

Publish and preview live

Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.