Of course, the standard WordPress search cannot keep up with the search results on Google & Co. With a few adjustments in the code and the right plugins, you can easily add a number of functions to your WordPress search. Here you will find a small compilation of practical options.
1. Handy code snippets
1.1. Show the search terms in the search result
I find it very helpful to be able to include the search terms on the results page. To do this, you simply have to add the following code snippet to your search.php file.
For the search terms ” ” there are the following search results:
More info: WordPress Codex: Function Reference/the search query
1.2. Show previous search term in search field
If you want the last search query to be displayed in the search field, you can adjust the value of the text input field in your search form (in the searchform.php file) as follows.
1.3. Show the number of search results
By default, the number of search terms found is not displayed on the WordPress results page. You can easily change this by modifying your search.php file as follows.
Search for the line of code:
and replaced the line with the following code:
found_posts; ?> Search results for
Further information: “Expand search result” by Frank Bültge.
1.4. Display a search text in the text field
If you would like to display a text such as “Enter search term here” or “Search…” in your search field, you simply have to adjust the value value in the input text field in your searchform.php file accordingly (you can use the code described in point 1.2 then of course don’t use it anymore).
So that this standard search text disappears when you click in the search field and reappears when you click on a subpage, you now have to insert onfocus and onblur in the input field as in the following code example.
2. Useful plugins for optimizing your WordPress search
2.1. Search Everything
»Search Everything« is one of the most comprehensive plugins to extend your WordPress search. You can highlight the search results in color and determine exactly which areas of your WordPress site you want to include or exclude in the search.
2.2. Search Unleashed
Similar to the “Search Everything Plugin”, with “Search Unleashed” you can define exactly which areas of WordPress you want to integrate into the search. The highlighting of the search terms in the results is also possible in this plugin.
The default search results for the WordPress search are sorted by the publication date. Instead, the »Relevanssi plugin« sorts the results according to the relevance of the results (depending on the number of search terms included).
2.4. Search By Category
The plugin allows blog visitors to limit their search to certain blog categories only. You can adapt the styles to your own design with CSS.
2.5. Page numbers with WP Page-Navi plugin
To integrate a practical page navigation with several pages of search results you can use the WP Page-Navi Plugin. To this you add
into your search.php file after installing and activating the plugin.
3. Use Google custom search engine
Alternatively, if you’re just not completely satisfied with the WordPress search results, you can integrate a custom Google search engine on your WordPress site. You can set up your individual Google search on this Google website (you need a Google account for this). As options you can specify which websites your search engine should integrate into the search. If you allow google ads to show in search results, google custom search engine is free. If you want to know what a custom Google search engine looks like in action, have a look at our Gertis PC Tips blog.
What do you think of WordPress search? Do you know other helpful ways to optimize the search function of WordPress? I really appreciate your feedback and tips!