Skip to Content

How to Remove the Search Bar in WordPress — Full Guide

How to Remove the Search Bar in WordPress — Full Guide

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.

 

How to Remove the Search Bar in WordPress

To remove the search bar in WordPress, remove the “search” widget from the sidebar. Some WordPress themes also offer an option to disable the search bar directly from within the theme. You can also hide the search field with CSS or with the help of the plugin “Disable Search.”

 

Check your Sidebar Widgets for a Search Widget

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 to see if a “search” widget is active.

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


 

Check your theme options for search bar 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 in WP themes that have the search button/function.

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

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

Other WordPress themes have similar options.

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 time and effort if the search bar can indeed be deactivated directly from within the theme options.


 

Disable the WordPress search bar with CSS

This is the next easy option for themes that do not have the toggle button to disable the search field.

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 mistake the underscore for a hyphen, it will not work.

The CSS to remove the search is:

#toggle-main_search {
display:none;
}

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 CSS elements than 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. 

To remove the search bar in WordPress when it isn’t a widget, use the following plugin:
 

“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 configure this.

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

Disable the WordPress search function with PHP

Alternatively, you can also disable the WordPress 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() {
unregister_widget('WP_Widget_Search');
}
add_action( 'widgets_init', 'remove_search_widget' );

The code above does not remove the search function entirely. It redirects searches.

The advantage of 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, and social media handles, or at least provide a link back to your home page.

Anything is better than nothing.