Better Search works out of the box. Install and activate it and you’re ready to go. By default, Better Search seamlessly integrates with your theme by overriding the main query to display relevant search results.
If you turn Seamless Mode off, then Better Search will look for a file called better-search-template.php
in your current themes folder. If this is found, the plugin will use this file, otherwise, it will default to the one hardcoded into the plugin. If you’re using a block theme aka Full Site Editing (FSE), then Better Search will look for better-search-template.html
instead.
The classic theme layout included within the plugin differs from the block theme template, primarily driven by the limitations of the extensive use of PHP. Let’s dive into each.
For Classic Themes
You can view the code behind the default template Better Search uses if your site uses a classic theme. Behind the scenes, Better Search uses Better_Search_Query
, a wrapper for WP_Query with additional settings needed for Better Search to fetch the relevant search results. This means that if you’re familiar with WP_Query
, then you only need to make a few minor tweaks.
For Block Themes
Block Themes use HTML files for templates. Create a better-search-template.html
file in your theme’s templates
directory. WordPress will automatically find and register the template for you. Better Search will use that instead of the one included in the plugin.
The template uses custom block patterns: better-search/search-form
and better-search/template-query-loop-news-blog
. The former displays a search form, whilst the latter displays the posts in a three column format.
Alternatively, you can keep seamless mode enabled and edit the search template for your site. The plugin registers a design called Better Search Results which you can find in the sidebar.