Skip to Content

How to Remove the Search Bar in WordPress — Your One-stop Guide

How to Remove the Search Bar in WordPress — Your One-stop Guide

Is your site thin on content? Every new WP install is. You can prevent users searching your site to be shown the “no posts found” message by learning about how to remove the search bar in WordPress. 

Most WordPress themes come with a pre-bundled search feature. It is usually inserted into the header area of the theme template.

If not, it will be bundled into the theme with pre-installed WordPress widgets.

Widgets are easier to remove than editing theme templates.

Either way, whichever theme you use, when you have no need for search functionality, you may as well remove it.

You do not want people to believe there may be more content available because the result will be “no posts found”. It is a giveaway that your site is thin on content.

For most static business websites that do not have many content pages, there is not much use for the search function.


How to remove the search bar in WordPress

The search bar can be removed from the sidebar by removing the “search” widget. Some WP themes have options to disable search. You can also hide the search field with CSS, or use the Disable Search plugin. Advanced users can edit the functions.php file directly, or use the Code Snippets plugin.


Check your widget area

The search bar can be coded into a WordPress theme template file, or it can be loaded by the WP search widget.

Go to the Appearance menu on your left sidebar, then select Widgets.

Look through the various widgets you have to see if there is a “search” widget already added.

If it is, click and drag it out of the active widget area.


Check your theme options

Some developers put some thought into how much customization can be done. The ones that make it easy give you an option within your theme customizer to disable the search feature.

One example is the Kale theme for WordPress.

The section to look for is menus. The primary nav menu or header menu are two common areas WP themes have the search button.

Go to appearance, select customize, then look for either menus or site navigation. Most will use those areas.

The Kale theme has a primary menu, secondary menu and for both, there is a “Kale Menu Settings”. This is the part to control the search function.

With a single click, the “Search Icon in Main Nav” can be toggled off. That disables the search feature.

Explore your theme customizer before proceeding to edit code because you could save a bunch of time and effort.


Disable the search bar with CSS

For themes that do not have the toggle button to disable the search field, this is the next easy option.

CSS is simpler to edit in WordPress than it is to manipulate template files.

Within your WordPress admin panel, there is a section for “additional CSS”. This overrides your theme stylesheet letting you hide elements.

The search field is an element. The hardest part is finding the name of that element to target with CSS.

Load your website in a new tab.
Right-click on the search field.
Click “inspect”.
Look for the “ID” name.

The ID for the Kale search in the menu is “#toggle-main_search”.

That code needs to be used as it is shown in the browser inspector.

Note the use of a hyphen and an underscore. Those need to be an exact match. If you happen to mistake the underscore for a hyphen, it will not work.

The CSS to remove the search is:

#toggle-main_search {

The ID will vary by theme. That is why you need to use the browser inspector.

This stops the search field from loading on the theme. What it does not do is delete the functionality.

Once your site has enough content to justify adding a search field, you can go back to your additional CSS and remove that code.

It is much easier to disable and reactivate elements in CSS than it is to recode theme templates with PHP.


How to remove the search bar in WordPress when it isn’t a widget

When the search bar is hardcoded into the theme, it uses the “get_search_form” WordPress hook.

function get_search_form( $args = array() )

Wherever this appears in the code for any template files, WordPress will first try to load the searchform.php file which controls the themes search functionality.

Deleting the file will not remove the search bar. The searchform.php file is only a custom file for the theme you are using. 

If you delete the searchform.php file, WordPress will load the default search form. That is in HTML only. Styling is minimal. 

Instead, use the…

Disable Search plugin

The advantage this plugin has is that it disables the search on the front-end, but keeps it working within the admin panel.

You can still search your WordPress database when logged in.

Install and activate and that is it. You do not need to do configure this.

All it does is strips the search function from the front-end of your theme.

Alternatively, disable the search function with PHP

For this method, you can either edit your functions.php file directly or use the “Code Snippets” plugin.

The Code Snippets plugin will write directly to your functions.php file, but only if there are no critical errors.

If there is an error in your PHP script, it will throw up an error message notifying you what line it is on. It will not apply bad code.

Putting the wrong code into your functions.php file will break your site. Using the Code Snippets plugin makes it harder to break your site. (That is not a challenge)

Use this code to disable search functionality in WordPress

function wpb_filter_query( $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', 'wpb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
function remove_search_widget() {
add_action( 'widgets_init', 'remove_search_widget' );

The code above is not removing the search function entirely. It is redirecting searches.

The advantage to this approach is that you get to avoid your site showing “no posts found” messages. Instead, it redirects traffic to your theme’s 404 page. That is something you can customize too.

Why would you want people going to an error 404 page?

You wouldn’t. But, it is better than a “no posts found” message.

Instead, you can customize your 404-page.php template to show a list of your most popular posts, your contact information, social media handles, or at least provide a link back to your home page.

Anything is better than nothing.