Skip to main content
Login Join
Snippet · PHP

Disable WordPress Search

Shared by Amit Dholiya · May 22, 2026

10 views
Back to Snippets

If your website doesn’t use the built-in WordPress search feature, you can disable it and redirect search requests to the homepage.

Steps

  1. Open your WordPress theme functions.php file.
  2. Add the code below at the end of the file.
  3. Save the file.
  4. Test by visiting a search URL such as ?s=test.

Done — visitors will be redirected to the homepage instead of viewing search results.

function disable_wp_search() {
    if (is_search()) {
        wp_redirect(home_url());
        exit;
    }
}
add_action('template_redirect', 'disable_wp_search');
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