How does WordPress Search work?
One of the most common methods that people use to find content online is a search. Whether they’re using Google to search for content or searching inside a website to find something specific, it’s important to make searching your WordPress site possible.
WordPress has two places you can search: on the live site using a widget or block, and inside your admin screens. Let’s take a look at each of those.
WordPress admin search
You can search for content when you’re in the admin listing screens for posts, pages, media and other post types. You’ll find the search box at the top right of the screen.
Type in part of the title of the post you’re looking for, hit the Search button, and a list of posts with that search term in the title will be displayed.
WordPress frontend search
There are multiple ways of adding a search field to your WordPress frontend, in this post we’ll cover the Search Gutenberg block, Search widget, and a manual custom code search field.
Search block
If you’re using a Gutenberg enabled theme you’ll be able to add a Search block to any post or page. Click on the plus (+) sign when editing the post and search for “search”, then select the Search block:
This will place the block directly into you page and allow you to add a placeholder, change the button label and tweak other options:
For full documentation please see: https://wordpress.org/documentation/article/search-block/
If you’re using a block theme and have the site editor enabled you will also be able to add this block into specific template parts like headers and footers. To do this simply go Appearance → Editor in your WordPress backend, then click on Template Parts → Header, this will open your header inside the Block Editor. This will allow you to make edits to the template part and insert other blocks such as Search, the process to do that is exactly the same as above!
Search widget
If your theme contains editable sidebars you will be able to create your own search widget and add it to that sidebar. For more general information on widgets, please see the WordPress theme handbook.
To add a search box to a configured sidebar on your site, use the Search widget. This comes with WordPress and you can add it to any widget area in your theme. It’s a good idea to add it somewhere near the top of the page such as in the header if there’s a widget area there, or at the top of the sidebar.
You can add text to the widget or just leave it blank. In your live site, it’ll display a search box people can use to search your content.
Custom code field
If you have FTP access to your website codebase or the Theme Editor enabled in your WordPress dashboard (as well as a little coding knowledge) you can manually insert a WordPress search function.
To do this navigate to your theme codebase, which is usually found in /wp-content → /themes → /your-theme. Find the header.php file and insert the following function:
<?php get_search_form(); ?>
Your search field should now be visible in the frontend, if you want to edit the HTML of the form this should be possible using the searchform.php template. Always ensure your site is backed up before making any file changes on a live site.
Enhancing WordPress search with a plugin
If you’re used to Google search, you’ll quickly get frustrated with the inbuilt WordPress search. It’s not as flexible and doesn’t take into account typos and misspellings.
A plugin such as Relevanssi can be installed to enhance the accuracy of your search results. The free version of the plugin comes with something called “fuzzy” search, this means instead of matching words exactly like they’re input, the search will return “close enough” matches allowing for mistakes and typos. Relevanssi comes with a whole host of features (some of which come with a premium price tag) allowing you to index and search through a greater variety of content, for the full list see Relevanssi features.
There are myriad plugins and platforms available designed to improve the user search experience and accuracy, some like Relevanssi can be integrated for free, others like Algolia, Elasticsearch and WPEngine’s own Smart search will come with a price tag and quite possible the need for technical input to integrate. They all boast very useful and impressive features such as AI integration, speed/performance improvements and accuracy/performance upgrades.
It’s an important part of the user experience on your site to be able to search – so whether you’re using the built-in search block/widget or a plugin, don’t forget to add a search box to your WordPress site.
Let's Talk
Do you have a web design and build project coming up that you would like to talk about?
Release of Clarity’s AI Values report
Fast Website Development Using Clarity Blocks
Let's Talk
Do you have a web design and build project coming up that you would like to talk about?