How To Create Amazing Search Functions For Your WordPress Blog
Create Better Search Results With These Handy Tips
A lot of people have been complaining over and over again about the bad WordPress search. Instead of complaining let’s simply create a nicer one which delivers better results. Before I go into the details I just want to note that most of the code below is taken from Joost de Valk’s excellent article about creating a better search. Be sure to take a look at it if you are serious about creating a better search.
The biggest problem people have with the default WordPress search is that it simply doesn’t pull up the results that are most relevant to the query. That’s the first problem we are going to address in this tutorial. The last part of this article simply shows you how you can make the search even more useful by using some cool tweaks.
This article was originally published at And Break but has been republished with Julius‘s permission.
More Relevant Search Results
The default WordPress search sucks and that’s the reason why I started to search for alternatives and came upon Search Unleashed. Search Unleashed is a litte bit more complicated than other search plugins but if you follow my advice it should be easy to set it up.
An alternative to Search Unleashed would be WP Search 2 (free & premium plugin) as well as Relevant Search, which is used by all the Tuts+ sites. All of these plugins deliver more relevant search results so it’s up to you to decide on one. The reason I stuck with Search Unleashed is because it’s extremely customizable. It also returns relevant search results as long as you know how to use it. It’s also free.
Basically Search Unleashed let’s you create your own search engine by giving you the option of deciding on priorities. You can do this on the Tools -> Search Unleashed -> Modules page.
If you, for example, think in order to get relevant results the keyword should be contained in the page title then you should assign this page title a high priority in order to reflect this. I chose 1 to tell the search engine that it’s the most important. You then go ahead and click on the things that you think are further important too, such as category, content, page excerpt, tags etc. and decide on a priority.
Configuring Search Unleashed

The priorities are as follows:
- Comment content: 0.1
- Post category: 0.5
- Post/page content: 0.7
- Post/page excerpt: 0.3
- Post/page slug: 0.2
- Post/page title: 1
You can actually see how the search is configured and the priorities assigned to each type. For me this combination works best but you can change it to whatever you want too. Once you have set the priorities be sure to save the settings.
Before any search results will be shown on your search page you need to go to the Search Unleashed page (Tools -> Search Unleashed) and re-index your site. This might take a few moments.
The next step is to change some additional options within Search Unleashed. The problem with the standard settings of the plugin is that it makes the search results extremely ugly. More importantly the search function hasn’t changed yet so it doesn’t deliver better results.
Go to the Search Unleashed -> Options page and change the Search Engine to MySQL Fulltext. If you don’t change this you will still be stuck with the default WordPress engine (which we know sucks). In order to also get rid of the ugly search excerpts uncheck both of these boxes:
- Change page title on search results to reflect the search condition
- Highlight searches on search page or default to the_excerpt
The last thing you need to do is to scroll further down the page and to change the color of Highlight Color #1 to #FEFFBF. That way the highlight is not too bright.
Create Better Search Excerpts
In order to get nice search excerpts you need to install the Search Excerpt plugin. All it really does is to create a nicer text excerpt of your article and highlighting the search terms. Once installed, activate it and it will show nicer excerpts automatically.
Style the Search Results Nicely
To get a nicer looking search page we are going to highlight the keyword within the heading of each search excerpt in order to make it stand out. A great addition to this is to also show the total number of relevant pages. To do that edit your search.php file (Appearance -> Editor -> search.php). Find the code which says the_title(); and change it to echo $title;. Then above it include the following code:
<?php
$title = get_the_title();
$keys= explode(” “,$s);
$title = preg_replace(‘/(‘.implode(‘|’, $keys) .’)/iu’, ‘<strong>

