[This was originally published at LouiseTreadwell.com on March 11, 2018.]
March 2018 is finally here and Google Site Search (GSS) is actually going away for good. While owners of larger websites have already happily settled into alternative premium services, some of us smaller guys have decided to retreat back to the comfort and predictability of WordPress’s built-in search engine. But, how do you restore the default WordPress search? Let’s take a peek under the hood and figure it out together.
Resetting the Search Form
This function can be placed into your theme file wherever you want the search form to appear.
This function will first attempt to load the file “searchform.php” but if it cannot find it in your main theme or child-theme, it will load the default WordPress search form. So, if you’ve customized or created the “searchform.php” file, renaming it (or deleting it) is one way to force your theme to load the default WordPress search form.
This will also cause any standard search widgets you have in your sidebars or footers to revert back to the default WordPress search form as well.
The default behavior of the standard WordPress search form will send your query to your homepage and attempt to display it there.
So the quickest route to get back to default is to:
- Rename or delete the file searchform.php in your child theme
- Add a Search widget into your sidebar OR edit your theme template to include the get_search_form(); function
- Run a search and see if you like the way your results display on your homepage.
The Search Results Page
What if the results look like rubbish? The search results are controlled by a file called “search.php” in your theme or child-theme. Take a look inside /wp-content/themes/your-child-theme/ or /wp-content/themes/your-parent-theme/ to see if there is a search.php file in there. If not, we’ll need to create one so we can improve the look of your search results page.
I’ll likely do a more intricate blog post about how to create a hyper-customized search results page, but for now, you want to look at your “page.php” file in your parent theme and use it as your guide to editing your “search.php” page. Here’s a quick start guide:
- Duplicate or create your search.php file into your child theme. (I like to name my old one search-bk.php just in case I need to refer to it later)
- Customize your new “search.php” file to beautify the display of your search results.
Want an example? Here is the one that I’ve created to use with the project I’m working on tonight:
&lt;?php get_header(); ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;div id="content"&gt; &lt;h1&gt;Search Results&lt;/h1&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div class="entry"&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt; &lt;?php else : ?&gt; &lt;h2&gt;No posts found.&lt;/h2&gt; &lt;?php endif; ?&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt;
Create a Custom Search Form
Are you also less than happy with the way your search form looks in your theme’s template pages or sidebars? No worries. We can customize that as well.
If you want to recreate a custom form, we’ll need to create or edit a file in your child theme named “searchform.php”. Your code inside of “searchform.php” should look something like this:
&lt;form action="/" method="get"&gt; &lt;label for="search"&gt;Search in &lt;?php echo home_url( '/' ); ?&gt;&lt;/label&gt; &lt;input type="text" name="s" id="search" value="&lt;?php the_search_query(); ?&gt;" /&gt; &lt;input type="image" alt="Search" src="&lt;?php bloginfo( 'template_url' ); ?&gt;/images/search.png" /&gt; &lt;/form&gt;
No other headers on it are needed. It can just float all alone on the page without any html or php headers as it will be dropped into your pages as-is.
So, there you have it. This is the bare minimum of what you need to know to restore your website back to using the default WordPress search tool. There are lots of plugins and premium services you can use to enhance your search, but this at least gets you back to square one.
Please let me know if you have any questions or notice any typos/bugs in this post!
Ready to go further? Check out part 2: “Block pages from showing in WordPress search results”