When a site has six pages, nobody needs to search it. When it has grown to dozens of blog posts, a long list of services and an archive of past newsletters, visitors start hunting through menus for something they know is there. A search box saves them the hunt.
You can add a search bar in WordPress in a few minutes with the Search block, and most themes offer a header search option as well. The steps differ between block themes and classic themes, so both are below. Before either, it helps to know what WordPress search will and will not find, because that decides whether the built-in search is enough.
Does your site need search?
Before adding anything, ask what visitors would type. If the honest answer is “your phone number”, a search box will not help them; a clear header will. Search earns its place when:
- you publish regularly and people come back for older articles;
- you list many products, services or locations;
- you have resources such as guides, price lists or FAQs spread across several pages.
It is one of the lighter additions you can make, since WordPress search is built in and the box itself is plain HTML. Even so, the checklist in our guide to adding new features to WordPress is worth a glance: decide where it goes and who will check the results.
What WordPress search actually looks at
By default, WordPress searches the title, content and excerpt of published posts and pages. It does not search custom fields, most widget or footer text, or the contents of PDFs. Results favour matches in the title and are otherwise sorted by date. If visitors will search for things that live outside the main content, plan for a search plugin (covered below). If search returns nothing for words you know are on the site, that is a separate problem, covered in our post on WordPress search returning wrong or no results.
Add a search bar in WordPress with a block theme
Here the header is built from blocks, so the search box is just one more block you drop into it through the Site Editor. WordPress’s own recent default themes all work this way.
- Go to Appearance → Editor, then open Patterns (or Template Parts, depending on your WordPress version) and choose your Header.
- Click into the header where you want the box, often to the right of the menu. Open List View if the layout is hard to click into accurately.
- Add a Search block using the inserter (the + button), typing “search” to find it.
- Use the block toolbar to set the button position and choose whether the button shows text or an icon. The sidebar has a width setting.
- Save. WordPress will tell you that you are changing the header template part, which affects every page using it.
- Open the site in another tab and check the header on desktop and on a phone.
Header edits in a block theme are saved to a shared template part; how template parts work, and how to reset one is worth reading before your first change.
Putting search inside the menu
The Navigation block can hold a Search block as one of its items. Select the Navigation block, use its add button, and choose Search. This places the box among the menu links, so it travels with the menu into the mobile overlay as well. Test the mobile menu afterwards; a search box squeezed into a narrow overlay may need the icon-only style. Our post on the WordPress mobile menu covers how that overlay behaves.
Classic themes: three common routes
Classic themes do not use the Site Editor, so the header is controlled by the theme. You have three common options.
1. The theme’s own header search
Many popular themes, Astra and GeneratePress among them, have a header or navigation search option in Appearance → Customize. Look under the header or navigation settings. Depending on the theme, the search shows as a full box, a magnifying glass that opens a field, or a full-screen overlay. This is usually the neatest route, because it is designed to fit the header.
2. A widget area
Go to Appearance → Widgets, pick a widget area such as the sidebar or a header widget area if your theme has one, and add a Search block. This suits blogs with a sidebar. Not every theme has a widget area in the header, so this route may only give you a sidebar or footer box.
3. A plugin that adds search to the menu
If your classic theme has no header search option, a plugin such as Ivory Search can add a search form to a menu, which you then manage alongside the menu under Appearance → Menus. The menu structure itself is covered in our post on creating a menu in WordPress. Check that the plugin’s box matches your theme’s styling on both desktop and phone.
Search block settings worth knowing
- Label. The word “Search” above the box. Hiding it visually is common in headers, but the field still needs a label that screen readers can announce; check that your setup keeps one when the visible label is switched off.
- Button position. Outside the box, inside it, no button, or button only. “Button only” shows a magnifying glass that opens the field when clicked, which saves space in a busy header.
- Icon or text. An icon is compact; the word “Search” is clearer for some visitors.
- Placeholder text. Use it to hint at what people can search: “Search guides and services”. Do not rely on it as the only label.
- Width. A box too narrow to show a few words feels cramped. On phones, let it take most of the row.
Shaping the search results page
A good search box leads to a poor experience if the results page is a jumble. In a block theme, open Appearance → Editor, find the Search Results template, and adjust it: show titles and short excerpts, hide large featured images if they push results off the screen, and add a short message and links for when nothing is found. In a classic theme the results layout comes from the theme, and its Customizer may have options for archive and search layouts.
When a search plugin is worth it
Built-in search is fine for many small sites. Consider a search plugin when:
- important information sits in custom fields, such as a product’s material or a property’s area;
- visitors misspell things and get nothing back;
- you want better ordering than “title matches, then newest”.
Two plugins owners often turn to here are Relevanssi and SearchWP; both can index more of your content and change how results are ranked. For WooCommerce stores, check whether your header search covers products only or the whole site, and decide which visitors expect. Set up any search plugin on a staging copy first, since it changes every results page at once.
Test it like a visitor
- Log out, or use a private window, since logged-in administrators and editors can see private pages in results that visitors cannot.
- Search for the name of a service, a post title, and one word that appears only in body text.
- Try it on a phone, from the mobile menu if you placed it there.
- Search for something you do not offer, and check the “nothing found” page is helpful.
Run the same four searches again after a theme change or a large update; it takes two minutes and belongs on the routine checklist in our WordPress help guide.
Frequently asked questions
Can I stop certain pages from appearing in search results?
Yes, though core WordPress has no simple switch for it. Many SEO and search plugins let you exclude a page or a whole content type from site search. Thank-you pages, test pages and old landing pages are common candidates. Keep in mind that excluding a page from site search does not hide it from Google; that is a separate setting.
Can I see what visitors are searching for on my site?
Some search plugins keep a log of searches, and Google Analytics can usually record site searches as events if the search address uses the standard search parameter. Reading those searches is one of the best ways to find missing pages or confusing menu labels, so it is worth switching on.
Should the search box be in the header or the sidebar?
For most business sites, the header is better, because it is in the same place on every page and on phones. A sidebar box suits blogs where readers browse articles. You can use both, but if space in the header is tight, an icon-only search that opens a field on click is a good compromise.
Why does the search box look different on my phone?
Themes often switch the header to a mobile layout, where a full box becomes an icon or moves into the menu overlay. That is usually deliberate. If it disappears completely, check whether the theme’s header settings have separate mobile options and whether search is turned on there.
The box itself is the quick part. Where a crowded header has no obvious room for it, the answer is usually a small change to the header layout rather than a bigger search plugin, and that sort of layout change is covered by our WordPress theme customisation service.
Next in this series: How to Add Breadcrumbs in WordPress: Plugin or Theme