Adding Google Search to WordPress Websites

Wordpress Software

I added a new function to the website, you may notice that in place of advertisements on the sidebar there’s now an option to search the domain with a customized Google search.

The template I’m using already has a WordPress search function in it, but there’s a few reasons I wanted to use Google’s results instead:

  • Monetize results pages
  • Better control of indexing
  • Cleaner looking results

Here’s a quick walkthrough of the implementation:

Go to Google Accounts

Go to Google Webmaster Tools

From Google Webmaster tools, select Custom Search to get started

Select the Initial Engine Information

Select the Initial Options

Set the general attributes of your search engine. These won’t necessarily appear on your WordPress website but they’ll be useful if someone stumbles across your engine (website) from looking around in the public Google display.

Set your Searched Domain(s)

Get the Code

Make sure its only searching your domain. If you want to set up a more thorough engine that includes related authority sites, that could be a useful resource for your readers, too. I’ve done a similar thing with a financial aid website I run, it searches only government and education domains to help students find scholarships and grants without going through too many commercial intermediaries (like me!)

Final Options and Get the Code for WordPress

Get the Code for your Blog

OK, there’s a lot going on here.

First, I’m going to choose to host the results on my own site because I don’t want to lose traffic. Next, I’m using the iframe and two page solution to manage the results display. I’ll explain this a little later in the implementation.

The next outlined section of text is the name of the URL that the results are going to be displayed from.  You can see I wrote /about/results/ but I actually ended up going with just /search/

From there, Google will add a /search/?dynamicurl=lookslikethis1c000623651 and serve a result

Next, I picked to place the ads on the top and the right.  Basically, this is the way Google does it and they do it because it generates the most clicks.

For the last part of the screen cap, the Search box Code, you can just toss that into a sidebar or whatever page you want to place it in (if you’re adding it to pages and posts, make sure to look at the HTML input on your admin screen)

Then, you’ll be making a page for the Search results code

Write a WordPress Search Results Page

Go to WordPress, write up a new Page (not post) and make sure that the page slug matches up with the result URL you told Google to display at.  (Remember, I changed my mind halfway through and went with /search/ instead of what I had in the earlier screencap)

Now, Go to the HTML view of your page and add the code you got from Google

If you want to display the results on a customized template, check out the next (optional) step:

Customized Search Page Template

For my implementation, I wanted to take the WordPress sidebars out of the Google search results page.  This requires WordPress page templates (full explanation at WP.org)

Basically, you can create a PHP file in the theme directory and declare a template name at the top of it.  Once that’s been done, you can assign that template to any page from that page’s edit UI.

In this case, I basically just took out the sidebars and kept the page low on code.

Monetize Google Site Search:

Go to the “Make money” tab and associate your search account with your Google adsense account.  Depending on your website’s niche, these search engine results can have a high value.  The Google-search style layout also generates a healthy click rate.

If you want to keep all of your traffic and have no ads, well you’ll need to prove you’re non-commercial or you’ll need to shell out $100 a year for the “premium” search service.

Keep the bots out:

Go to robots text and Disallow the directory that displays the search results.  eg:  DISALLOW /search/*

Barring any unexpected errors, that should be a search-engine friendly solution to having your own Google based search engine on a WordPress website.  It helps your visitors find what they’re looking for, and if that isn’t on your site it will make you some money anyway!

4 Comments

  1. This is a good way to make some income on your blog by adding a search feature powered by google. Just make sure you can blend it in with your blogs user interface design so it looks seamless. If you are familiar with java script code you can snip out some sections to give the search bar a cleaner look with your blog.

  2. I had it set up with my last template but now I’m running out of excuses since I’ve been using this one for a while now… 🙂

    This new template has Google search built in, so I’d have to mess with the theme functions to get it working again.

    Thanks for bringing that up though, it would be a nice little improvement and I might learn an extra thing or two about WordPress functions too!

Leave a Reply

Your email address will not be published.


*