Learning how to add a search bar to a WordPress theme is one of the most practical skills you can develop as a site owner or developer. A well-placed search bar improves user experience, reduces bounce rates, and helps visitors find exactly what they need without frustration. In this guide, you will learn every major method — from drag-and-drop widgets to custom PHP code — so you can choose the approach that fits your workflow and theme.
Why Adding a Search Bar to Your WordPress Theme Matters
A search bar is not just a convenience feature; it is a critical navigation element. Studies consistently show that users who engage with on-site search are more likely to convert, spend more time on the site, and return in the future. Without a visible search option, visitors who cannot find content through menus will simply leave.
WordPress comes with built-in search functionality out of the box. The challenge is not building the search engine itself — WordPress handles that — but rather placing the search input field in the right location within your theme. The method you use depends on your theme structure, your comfort with code, and how much customisation you need.
Method 1: Add a Search Bar Using the WordPress Widget System
The easiest way to add a search bar to a WordPress theme is through the built-in widget system. This requires no coding and works with almost every theme that supports widget areas such as sidebars and footers.
Adding the Search Widget via the Block Editor (WordPress 5.8+)
- Log in to your WordPress dashboard.
- Navigate to Appearance > Widgets.
- Locate the widget area where you want the search bar to appear, such as Sidebar or Footer.
- Click the plus (+) icon inside that widget area to add a new block.
- Search for "Search" in the block inserter and click the Search block.
- Customise the placeholder text, button label, and button style using the block settings panel on the right.
- Click Update to save your changes.
Adding the Search Widget via the Classic Widget Interface
- Go to Appearance > Widgets in your dashboard.
- Find the Search widget in the list of available widgets on the left.
- Drag it into your desired sidebar or footer widget area on the right.
- Give it an optional title, then click Save.
This method is instant and reversible. However, it limits your search bar to pre-defined widget areas. If you want the search bar in the navigation menu or header, you will need one of the methods below.
Method 2: Add a Search Bar to the Navigation Menu
Many modern WordPress themes place a search icon or input field directly inside the header navigation bar. This is a high-visibility placement that users expect and appreciate. There are two common approaches: using the Customizer or editing theme template files.
Using the WordPress Customizer
- Go to Appearance > Customize.
- Look for a section labelled Header, Header Options, or Navigation — the exact name depends on your theme.
- Check whether your theme offers a built-in Search Icon or Search Bar toggle. Many premium themes such as Astra, GeneratePress, and OceanWP include this option natively.
- Enable the search option, adjust any styling settings provided, and click Publish.
If your theme does not offer this in the Customizer, you will need to edit template files or use a plugin.
Adding Search to the Menu via a Plugin
Plugins like WP Search Bar or Search Everything can inject a search form into your menu without touching code. Install the plugin, configure its settings, and assign the search bar to your header menu position. This is a reliable middle ground between using widgets and writing custom PHP.
Method 3: Add a Search Bar Using PHP Code in Theme Files
For developers or advanced users, adding a search bar directly to theme template files gives you the most control over placement and markup. WordPress provides a dedicated template tag and a dedicated template file for search forms.
Using the get_search_form() Function
The get_search_form() function outputs WordPress's default search form. You can call it anywhere inside a theme template file. To add a search bar to your header, open your theme's header.php file and paste the function where you want the form to appear.
<?php
// Place this inside header.php where you want the search bar
get_search_form();
?>
This single line renders the complete search form using WordPress's built-in searchform.php template if it exists in your theme, or falls back to a default HTML structure. It is clean, semantic, and automatically integrates with your theme's styles.
Creating a Custom searchform.php Template
If you need full control over the HTML markup of the search form — for example, to match a specific design system or add accessibility attributes — you can create a custom searchform.php file inside your theme folder. WordPress will automatically use this file whenever get_search_form() is called.
- Open your theme directory, for example
wp-content/themes/your-theme/. - Create a new file named
searchform.php. - Add your custom HTML markup for the form, including the required attributes WordPress expects.
- Save the file and refresh your site to see the custom form rendered.
<!-- Custom searchform.php -->
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ); ?></span>
<input type="search"
class="search-field"
placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ); ?>"
value="<?php echo get_search_query(); ?>"
name="s"
aria-label="<?php echo esc_attr_x( 'Search for:', 'label' ); ?>" />
</label>
<button type="submit" class="search-submit">
<?php echo esc_html_x( 'Search', 'submit button' ); ?>
</button>
</form>
Important: Always edit a child theme rather than the parent theme directly. Changes to parent theme files are overwritten when the theme updates. Create a child theme first, then add or modify template files within it.
Adding Search to a Specific Page Template
If you only want the search bar on specific pages — for example, a blog archive or a 404 error page — open the relevant template file such as archive.php or 404.php and call get_search_form() at the appropriate location. This gives you surgical control over where search appears without affecting the rest of your site.
Method 4: Add a Search Bar Using the Full Site Editor (Block Themes)
WordPress block themes, introduced with the Full Site Editor (FSE) in WordPress 5.9, handle search bars differently from classic themes. Everything is managed through blocks rather than PHP template files.
Adding Search to the Header Template Part
- Go to Appearance > Editor in your WordPress dashboard.
- In the left-hand navigation, click Template Parts, then select Header.
- Click inside the header area to edit it.
- Click the plus (+) block inserter and search for "Search".
- Add the Search block to the position you want — typically next to your navigation menu or site logo.
- Customise the block settings: choose between a button inside or outside the input, set the button text, and adjust width settings.
- Click Save to apply changes to all pages that use this header template part.
The Full Site Editor approach is entirely visual and does not require any code. It is the recommended method for block themes such as Twenty Twenty-Three, Twenty Twenty-Four, Kadence, and others that fully support FSE.
Method 5: Enhance WordPress Search with Plugins
The default WordPress search is functional but limited — it only searches post titles and content by default. Several plugins can both add search bars to your theme and dramatically improve what gets searched.
Recommended Search Plugins
- SearchWP: Extends WordPress search to include custom fields, taxonomy terms, WooCommerce products, and PDF content. Highly configurable with a visual relevance editor.
- Relevanssi: A free plugin that replaces the default WordPress search algorithm with a more accurate, fuzzy-matching engine. It also searches comments and custom fields.
- Ajax Search Lite: Adds a live, real-time search bar with auto-complete suggestions. It can be placed in widgets, shortcodes, or template code.
- FiboSearch: Purpose-built for WooCommerce stores. Displays product images, prices, and categories in the search dropdown as users type.
Installing and Configuring a Search Plugin
- Go to Plugins > Add New in your dashboard.
- Search for your chosen plugin by name and click Install Now, then Activate.
- Navigate to the plugin's settings page (usually under Settings or its own top-level menu item).
- Configure which content types and fields the plugin should index.
- Use the plugin's provided shortcode or widget to place the enhanced search bar in your theme. For example, Ajax Search Lite uses the shortcode
[wpdreams_ajaxsearchlite]. - Test the search bar on the front end to confirm results are accurate and the interface works correctly on mobile devices.
Frequently Asked Questions
How do I add a search bar to the WordPress header without a plugin?
Open your theme's header.php file (inside a child theme) and add <?php get_search_form(); ?> where you want the search bar to appear. For block themes, use the Full Site Editor to add a Search block to the Header template part — no code required.
Why is the search bar not showing on my WordPress site after adding it?
The most common causes are a caching plugin serving an old version of the page, the widget area not being active in your current theme, or the template file edit being made to the parent theme instead of a child theme. Clear your cache, verify your theme supports the widget area you used, and always edit files in a child theme.
Can I add a search bar to a specific page only in WordPress?
Yes. Create a custom page template in your child theme, call get_search_form() at the desired location within that template, and assign that template to your specific page via the Page Attributes panel in the WordPress editor. Alternatively, use a shortcode plugin to insert a search form via shortcode on any page.
How do I style the WordPress search bar to match my theme?
Add CSS rules targeting the default classes: .search-form, .search-field, and .search-submit. Add your custom CSS via Appearance > Customize > Additional CSS or in your child theme's style.css file. If you used a custom searchform.php, you can apply any class names you defined there.
Adding a search bar to your WordPress theme is a straightforward task whether you prefer a no-code widget approach, theme Customizer settings, PHP template editing, the Full Site Editor, or a dedicated plugin. Each method has its place depending on your theme type and technical comfort level. If you want an even faster way to make changes like these without manually editing files or navigating menus, WP AI Agent is a powerful tool that lets you handle WordPress tasks — including adding and configuring search bars — through simple natural-language AI chat, making site management accessible to everyone.