How to Disable Search in WordPress

WordPress includes a built in search feature on every site, whether you want it or not. Visitors can type a word into the search box or visit a search URL and see a results page listing your posts. That sounds useful, but for many sites it creates more problems than it solves. Search results pages are thin pages that add little value, they can be abused by bots that request thousands of search URLs, and they can expose content you would rather keep out of a public listing.
Disabling search is a sensible step for a small business site, a landing page, a portfolio, or any site where visitors navigate by menu instead of search. It is also useful when you replace WordPress search with a better tool, such as a Google custom search or a dedicated search plugin that you control. In this guide you will learn how to remove the search box, how to turn search URLs into a 404 page with a small PHP snippet, how to hide the form with a filter, and how to remove the search widget from classic themes, all without installing a plugin.
Before you start, make a full backup and note that disabling search only affects the public front end. The search box inside your WordPress admin area keeps working, so you can still find posts, pages, and media when you manage the site. If your site relies on search for a shop or a large blog, do not disable it. Read our web hosting guide first if you are unsure about editing theme files, because a bad edit can take a site offline.
How do I remove the Search block in a block theme?
Block themes put the search box in templates and template parts, not in a widget area, so you remove it in the Site Editor. Go to Appearance, then Editor, in your WordPress admin area. Open the template or template part that contains the search box, which is usually the Header template part or the Search Results template. Click the Search block to select it, then press Delete on your keyboard or choose Remove block from the block toolbar menu.
Save the template when you are done, then visit your site and confirm the search box is gone from the header, the sidebar, and the footer. If your theme shows a search icon instead of a full box, that icon may be a separate block or part of the Navigation block, so check the Navigation block settings too. Some themes add search through a pattern, so you may need to remove it from more than one template part.
Removing the block only hides the visible form. It does not stop anyone from visiting a search URL directly, such as yoursite.com/?s=keyword. A visitor or a bot can still load that URL and see results. That is why you should combine this step with the PHP snippet in the next section, which blocks the search request itself. Removing the block plus blocking the URL gives you a complete result.
How can a PHP snippet turn search URLs into a 404 page?
The most reliable way to disable WordPress search without a plugin is a small snippet that runs on the parse_query hook. WordPress builds a query object for every front end request, and this hook lets you inspect that query before any posts are loaded. If the query is a search query on the front end, the snippet tells WordPress to treat it as a 404 page instead. The visitor sees your normal 404 page, search engines see a 404 status, and no search results are generated.
Add the code below to your child theme functions.php file or to a code snippets plugin set to run on the front end. Always back up before editing functions.php. A syntax error in that file can lock you out of the admin area, and you would need to remove the code through your hosting file manager to recover.
<?php
add_action("parse_query", function ($query) {
if (!is_admin() && $query->is_main_query() && $query->is_search()) {
$query->set("post_type", "none");
$query->is_search = false;
$query->is_404 = true;
}
});
Test the snippet by visiting yoursite.com/?s=test in a private browser window. You should see your 404 page instead of search results. Also test a normal post, a page, and a category archive to confirm they still load correctly. The snippet checks is_admin first, so the search box inside the admin area keeps working, and it checks is_main_query, so it does not break secondary queries used by widgets or related posts.
If you already have a custom 404 page, this snippet will use it automatically, which is a good reason to have one. Our guide on how to create a custom 404 page in WordPress shows you how to build one that helps lost visitors find the right page instead of leaving.
How do I hide the search form with a filter?
Some themes and plugins call the search form through the get_search_form function instead of placing a Search block. In that case removing the block will not hide the form, because the form is printed by code. The get_search_form filter lets you replace that output with nothing, so the form never appears on the page even if a template asks for it.
<?php
add_filter("get_search_form", "__return_empty_string");
This one line filter is short and safe, but it only hides the form. It does not block search URLs, so use it together with the parse_query snippet above for a complete solution. If you only use this filter on its own, a visitor can still reach search results by typing a search URL directly, even though no form is visible on the site.
How do I remove the search widget in a classic theme?
Classic themes show the search box through the Search widget in a sidebar or footer widget area. You can remove it in Appearance, then Widgets, by opening the widget area and deleting the Search widget. That is enough if you only use the widget in one place, but some themes register the widget in code and show it even after you delete it from the sidebar.
To unregister the widget completely, add this snippet to functions.php or to a code snippets plugin. It runs on the widgets_init hook and removes the WP_Widget_Search class from the list of available widgets.
<?php
add_action("widgets_init", function () {
unregister_widget("WP_Widget_Search");
});
After adding the snippet, check every widget area on your site, including the footer and any custom sidebars added by your theme. If a search box still appears, it may come from a block, a template file, or a plugin, so search your theme files for the text get_search_form to find the source. For more ways to lock down a WordPress site, read our guide on how to disable XML-RPC in WordPress and our guide to enable WordPress debug mode when you need to trace a problem safely.
Will disabling search break anything on my site?
For most small sites the answer is no. Posts, pages, categories, tags, menus, and the admin search all keep working normally. The only thing that changes is the public search feature. Visitors who try to search will see a 404 page, and any link to a search results page will stop working. That is the intended result, but you should plan for it.
- Check that no menu item, button, or footer link points to a search URL before you disable search.
- Check that no plugin depends on WordPress search, such as a live search plugin or a shop filter that uses search queries.
- Update your 404 page with helpful links so visitors who expected search can still find content.
- Test the site on a phone after the change, because mobile menus sometimes include a search icon.
WooCommerce sites need extra care. The shop search uses the same WordPress search query in some themes, so disabling search site wide can break product search. If you run a shop, either keep search enabled or use a WooCommerce specific search replacement instead of the site wide snippet. Test the shop search thoroughly on a staging site first. Our guide on how to create a WordPress staging site without a plugin shows you how to test safely.
Should I block search URLs in robots.txt?
No, do not block search URLs in robots.txt. That sounds like a tidy way to keep search pages out of Google, but it causes a different problem. When you disallow a URL in robots.txt, Google cannot crawl it, but it can still index the URL if other sites link to it, and it may show the URL in results without a description. You also lose the clean 404 signal that tells Google the page is gone.
WordPress has handled this correctly since version 5.7. It automatically adds a noindex tag to search results pages, which tells search engines not to index them. That is the right signal, and you do not need to add anything yourself. Once you disable search with the parse_query snippet, search URLs return a real 404 status, which is an even clearer signal that the page does not exist. Let the 404 and the built in noindex do the work, and leave robots.txt alone for this.
For the official reference on the search query and the hooks used here, see the WordPress developer documentation. It documents parse_query, get_search_form, and the widget API used in the snippets above.
How do I bring search back later?
Disabling search with code is easy to reverse. Remove the snippets from functions.php or turn off the code snippet, then add the Search block back in the Site Editor or add the Search widget back in Appearance, then Widgets. Clear your cache and test a search URL to confirm results appear again. Because you did not delete any content, nothing is lost, and search returns immediately.
Frequently Asked Questions
Does disabling WordPress search improve performance?
It can help a little, mainly by stopping bots from hammering search URLs that generate expensive database queries. The gain is small on a quiet site and larger on a site that gets a lot of bot traffic. It is not a replacement for caching, image optimisation, or a good host, but it removes one easy target for abusive requests.
Will admin search still work after I disable search?
Yes, admin search still works. The parse_query snippet checks is_admin first and only changes front end queries, so the search boxes in Posts, Pages, Media, and other admin screens keep working exactly as before. You can still find content when you manage the site.
Can I disable search only for logged out visitors?
Yes, add a check for is_user_logged_in inside the parse_query snippet and only set the 404 when the visitor is logged out. That keeps search available for members or staff while hiding it from the public. Test both states in a private window and in a logged in window to confirm the behaviour is correct.
Do I need a plugin to disable WordPress search?
No, you do not need a plugin. Removing the Search block, adding the parse_query snippet, and using the get_search_form filter covers the whole job. A plugin only makes sense if you want a settings page to toggle search on and off without touching code, or if you want to replace search with a different search tool.
Last updated: November 2026.



