How to turn your boring and imprecise WordPress search into a cool, accurate, and mildly profitable Google search

The normal search that is included with lots of WordPress themes is pretty inaccurate in terms of the results it shows. Users often can’t see the word they’ve searched, they only get a list of posts in which their search term is contained. If they don’t know how to Ctrl or Apple-F to find the term, then the results won’t show them a thing. In these days where people are used to Google’s clean, accurate, and easy interface for searches, it is a shame not to provide the same kind of results on your own site, especially when all the tools are readily available. You’ll need:

  • A self-hosted WordPress blog
  • A Google AdSense account
  • A theme with a search box, or you can just add your own
  • pageMash plugin (optional: to easily hide your results page if you have a page menu)
  • Knowledge of how to edit both ordinary pages and your theme’s template
  • About 30 minutes

Step 1. Set up a Google adsense account if you don’t have one, and add a Custom Search Element

Google Custom Search control panel

Google Custom Search control panel

Note: make sure you choose a custom results page spelled exactly as you will use it in this step, if you choose to create a new results page.

The AdSense for Search element consists of two parts: one is the search box and one is the results page. The search box usually sits somewhere on your index page and is made up of a form window and a button (see below for example)

A typical search box

A typical Google search box

The results page is a separate page that displays the Google results.  When you finish setting up your Adsense for Search, you’ll be presented with paste code for both search box and results.  Copy the search box code and paste anywhere in your template. Here are some suggestions for where to put it (remember to use entire code):

  1. In a custom widget – go to widgets, select “Text” and paste code into the box
  2. In your header – paste somewhere in your header.php file so the search box is visible from all pages. You’ll need to know a bit about how to format your header.php file.
  3. In your theme’s searchform – some themes have a file called searchform.php (or something similar) that basically contains the code for the WordPRess search form. You can replace that with Google’s code.
This theme has search pages included

This theme has search pages included

The result code will be pasted on a new page. It’s best to use a new page from WordPress’ admin panel.  Some themes have a built-in search result page (often called search.php) that is used for the default search system, but I’ve found that trying to paste the Google code into that page will yield a 404 error.

Step 2. Hide your results page

For some reason, WordPress doesn’t yet allow you to hide pages from being shown in page menus.  If you have a site that is page-based, you’ll notice that your new search page will appear in the menu: not desirable since it can’t be used on its own.  The pageMash plugin for WordPress will let you move, reorder, and hide pages from the menu (see below). There are surely other ways to accomplish this, but pageMash is my favorite. Download and install it.

Hide search results page using pageMash's interactive menu

Hide search results page using pageMash's interactive menu

As you can see in the above example, I have called my results page “Search Results from”. This is so that users will know that they are only getting results from my site and not from the entire web. A site’s custom Google results can sometimes confuse people since they resemble ordinary results.

Things to note and remember:

1. If your site has a content area less than 795 pixels wide, you may need to choose a Search Results format with the ads above and below (instead of to the side).  Although this isn’t made clear, results with the default side ad placement must be a minimum of 795 pixels wide. Most blogs have content that is much narrower when taking into consideration the sidebar.

2. You can customize the colors and the layout of both the search box and results. You can match it to your current site, and choose from a variety of buttons.

3. Don’t forget to add a custom results page when setting up your Adsense for Search. The page could be called anything, but something easy such as “results” would be a good idea. Later, when you need to create that page manually, you will easily be able to.