# Disabling default search in WordPress using PHP

> Turn off the built-in WordPress search feature with a short PHP snippet, useful for one-page or landing-page sites.

Source: https://helpcenter.ruachost.com/wordpress/guides/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.

## Why Disable Search?

- 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.

## Steps to Disable Search via PHP

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.

## Important Notes

- 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.
