Skip to main content
Login Join
Snippet · PHP

Block Search Query Access

Shared by Darshit Rajyaguru · May 22, 2026 · @init

1 copy
34 views
1 upvote
Back to Snippets

Prevents public search queries using ?s=.

function dr_block_search_query() {
    if ( isset( $_GET['s'] ) && ! is_admin() ) {
        wp_redirect( home_url() );
        exit;
    }
}
add_action( 'init', 'dr_block_search_query' );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments