Implementing Google Custom Search on WordPress
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.
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.
About Tom Johnson
I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.
If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.