Implementing Google Custom Search on WordPress
January 8th, 2010 | Posted in blog 13 Comments »
Google Custom Search can dramatically improve the search results for your WordPress blog or any other site. WordPress is a great blogging platform, no doubt about it. But the built-in search feature is terrible. As I’ve searched for keywords from past posts to respond to reader questions, I would continually come up empty-handed.
As a solution, I incorporated Google Custom Search, which is a free service that allows you to embed a Google search box and results (limited to just your site and any other sites you specify) on your site.
Try it out by searching for something using the search at the top of my sidebar. Not only are the search results more accurate, when you start running a few searches, you begin to see how your site appears to people who search for you in Google.
Canonical Posts
One thing I immediately realized was that a lot of my archives pages were appearing in posts. The search results would begin with my blog title followed by the word archives followed by the post title (which was then truncated due to space constraints). It’s important to have just one version of your post in Google’s search results, so that your other posts aren’t competing against each other. (For more on this, research canonical URLs in WordPress.) I also wanted the search engine result to begin with the post title.
To fix the display of the results, I implemented the All in One SEO plugin and configured the plugin’s settings so that only the single post would appear in the search results, not the archives. I then created a sitemap (using the Daigon Design sitemap generator as well as the Google XML Sitemap plugin), generated both sitemaps, and linked to the Daigon Design sitemap in one of my latest posts so that Google would reindex all the posts on my site.
Implementing Google Custom Search
Implementing Google Custom Search in a WordPress site can be a little tricky. The Google Custom Search WordPress plugin didn’t work for me, so I just copied the Google code manually.
Google gives you two pieces of code: code for a search box and code for the search results. Choose the iframe option before generating the code. For the search results page, type the name search. Insert the search box code in your sidebar somewhere. Then create a page called Search that uses a page template with the search results code. Also copy the search results code into the search.php page of your theme.
As you accrue more and more posts in your blog, you need an fast and accurate way to retrieve posts based on vaguely remembered keywords. WordPress’s built-in search won’t always find what you’re looking for. If users are savvy, they can use site:yourdomain.com keywords to search your site at Google.com. But embedding the search form directly on your site is much more user-intuitive.
Sponsors
Tags: canonical, Google, google custom search, search engine optimization, search results, Web Design, WordPress
If you liked this post, keep updated with new content: Subscribe to I'd Rather Be Writing.
Both comments and pings are currently closed.

















[...] rest is here: Implementing Google Custom Search on WordPress | I'd Rather Be … var AdBrite_Title_Color = '006DAD'; var AdBrite_Text_Color = '000000'; var [...]
Thanks for the information. I have been tweaking my blog and looking for ways to make it better. I have heard that the WP search wasn’t all that, so I appreciate the review on a better option.
Tom,
If you want to monetize GCS, you can tell Google to search site 1, site 2 and site 3.
Then, when someone goes to these sites, if a person clicks the links, you’ll make money from the Adsense fees.
Many sites/blogs are structured so that the user is ‘encouraged’ to search, i.e. so they click on the results + generate fees to the webmaster.
Ivan
I think having this on your blog is very helpful for your users, rather than opening a new tab etc they can just search straight from your blog!
I did what you have written but couldn’t get through. Is there any css tweak too?
You know, I tried a lot of different things to get it to work, and now I can’t remember what the magic tweak was. Basically, I believe that creating that page within WordPress’s pages (not just a file within the theme) was helpful.
[...] on google.com resolves…), but there is a plugin you could try. If that doesn't work, Google found these posts on doing it yourself that look quite good. __________________ Pole Exercise – Pole [...]
I think Google has changed the setup. I didn’t get an iframe option, and only one bit of code to paste in.
Any chance you’d update the directions? I tried to figure it out myself to put a Google Custom Search bar at the top of my sidebar, but I just can’t get it with their new stuff.
Found the answer on another site — once you’ve set up the GCS, click on the “look and feel” link, then you can choose the iframe, etc.
Between both sets of info, maybe I’ll get this to work!
The one issue I have found is that Google Custom Search indexes the sidebar content too. So, if you have a Popular Posts or Recent Posts section, every page will show up when someone searches for a word in the title of a topic in one of those lists. I have not found a way to exclude sidebar content from Google search.
SEO helps list the best article at the top, but you still get the other hits below that are very misleading.
Hmmm, I wasn’t aware of that. Thanks for the note. I haven’t really revisited the Google integration since integrating it into the site. It seems to help me find posts I’m looking for, most of the time. Ideally, I’d like to do a much better job making the 1,000 plus posts on my site visible, though.
Here’s the only article I could find on this topic:
http://www.google.com/support/forum/p/customsearch/thread?tid=7b512d30806b992d&hl=en
Try adding a sitemap to your blog (both Google XML Sitemaps and Daigon Design Sitemaps), and then post a new blog post linking to the sitemaps. When Google indexes your new blog post, it will index the content the post links to as well. Then wait about 2 weeks to see the results.