Skip to content

Disabling default search in WordPress using PHP

On some WordPress sites—such as one‑page websites, landing pages, or sites with limited content—the default search function may not be useful. You can disable it using a simple PHP snippet. On ruachost.com, this is a safe way to remove the search feature without breaking your theme.

  • Prevents users from seeing irrelevant “No results found” pages.
  • Simplifies navigation for one‑page or static sites.
  • Reduces clutter in the WordPress dashboard and front‑end.
  1. Log in to WordPress with an administrator account.

  2. In the dashboard, go to Appearance → Theme Editor.

  3. Select your active theme and open the functions.php file.

  4. Add the following code snippet at the end of the file:

    // Disable WordPress default search
    function disable_search($query, $error = true) {
    if (is_search()) {
    $query->is_search = false;
    $query->query_vars['s'] = false;
    $query->query['s'] = false;
    if ($error == true) {
    $query->is_404 = true;
    }
    }
    }
    add_action('parse_query', 'disable_search');
    add_filter('get_search_form', function($a) { return null; });
  5. Click Update File to save changes.

  6. Test your site → The search function will now be disabled.

  • Always back up your theme files before editing.
  • Use a child theme to preserve changes during updates.
  • This method disables both the search form and search queries.
  • If you want to re‑enable search later, simply remove the code snippet.