How to disable search in WordPress

Not every site needs a search. A portfolio, a landing page or a small business site with a handful of pages has nothing worth searching, but WordPress answers every search URL anyway. Add ?s=anything to the address of any WordPress site, and you get a search results page, whether the theme shows a search form or not. Pages you figured were inaccessible just because they’re not linked anywhere can still show up through the search page. Spammers use the search page to put their links and phrases on other people’s sites, in the hope that the page ends up in Google.

In this tutorial, we’ll remove the search form from the theme, turn off the search itself with a short snippet, and go through what WordPress already does to keep search pages out of Google.

Removing the search form from your theme

In a block theme, the search form is a Search block, and where it is depends on the theme. Some have one in the header, others in a sidebar, the footer or the 404 template. To remove it:

  1. Go to “Appearance” → “Editor” → “Templates”, and open a template that shows the search form.
  2. Open the List View with the icon in the top left, and find the Search block. If it’s in the header or the footer, it’s inside that template part, so you’ll need to expand it in the List View.
  3. Select the Search block, open its options menu (the three dots in the toolbar), and select “Delete”.
  4. Click “Save”.

Repeat this for every template with a Search block. If you removed it from a template part, like the header, the change applies to every template that uses it.

This only removes the form. The search itself still works for anyone who types a search URL, which is exactly what spammers do. To turn it off completely, you need a few lines of code.

Turning off search completely

This snippet makes every search URL return a “Page not found” error, and hides the search form wherever it shows up. Save it as disable-search.php in the wp-content/mu-plugins folder of your site (create the folder if it doesn’t exist). Must-use plugins are loaded automatically, so there’s nothing to activate, and the code keeps working if you switch themes.

<?php
/**
* Plugin Name: Disable search
* Description: Turns off the public search on the front end.
*/
// Treat search URLs as pages that don't exist.
add_action(
'parse_query',
function ( $query ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() ) {
return;
}
$query->set( 's', '' );
$query->set_404();
status_header( 404 );
nocache_headers();
}
);
// Hide the Search block, and the search form in classic themes.
add_filter( 'render_block_core/search', '__return_empty_string' );
add_filter( 'get_search_form', '__return_empty_string' );

The first part catches search requests before WordPress runs the search, empties the search term, and shows your 404 page instead. That covers every way to search: ?s= in the address, pretty URLs like /search/anything/, search feeds, and paged results. Since the search term is emptied before WordPress runs the search, spam requests don’t make it search through your posts either.

The last two lines hide the search form, so you don’t have to remove it from every template by hand. The first one covers the Search block, and the second the search form and widget in classic themes.

If you’d rather use a plugin, Disable Search does the same thing, and also removes the Search block from the editor. It hasn’t been updated since April 2025, though, so check that it’s still maintained before you rely on it.

Search spam and Google

Search spam works like this: a bot links to search URLs on your site with spam in the search term, like ?s=cheap+watches+example.com. Your search results page then shows “Search results for: cheap watches example.com” on your domain, and if Google indexes the page, the spammer gets their words in front of searchers with your site’s name next to them.

WordPress has protected against the indexing part since version 5.7, by adding a noindex tag to every search results page. So even if you keep search on, those pages shouldn’t end up in Google. With the snippet above, the URLs return a 404 instead, which tells Google there’s nothing there at all.

One thing to avoid: blocking search URLs in robots.txt. It sounds like the right move, but it stops Google from visiting the pages, so it never sees the noindex tag or the 404. Pages blocked in robots.txt can still be indexed if other sites link to them, which is exactly what spammers do.

Notes

  • Search in the admin keeps working. The snippet only affects the front end, so you can still search your posts, pages and media in the admin.
  • The editor’s search keeps working too. When you add a link in the editor, WordPress finds posts through the REST API, which the snippet doesn’t touch. That also means the REST API still answers search requests, but it only returns titles and links you’ve already published, not a page on your site.
  • The Search block is still in the editor. You can still add one, and it shows up in the editor, but the snippet hides it on the site.
  • The Search Results template stays. You can leave it in place, since nothing will use it.
  • On WordPress.com, you need a plan that lets you add plugins to use the snippet.
  • Want to keep your site out of Google instead? That’s a different setting. I go through it in my tutorial on how to discourage search engines from indexing your site.