The native WordPress search does not return very relevant results, thus it makes a lot of sense to add Google Search into your WordPress Blog. In addition, Google Search can be easily integrated with Google AdSense.
There are a variety of plugins that allow you to integrate Google Search into your WordPress Blog. I have chosen to use the ‘Search API’ Plugin that was developed by Justin Shreve and Andy Skelton at WordPress.
This blog, as well as my ShibaShake website are both using the Search API/Google plugin, so feel free to test it out by doing a search on this page or on the ShibaShake homepage.
The Search API Plugin is a WordPress developed plugin, and much of the API code will likely be included in future versions of the WordPress Core. WordPress developed plugins tend to be well supported and often get updated across new WordPress releases.
However, you may need to make some changes to the Search API Plugin so that it integrates properly with your current WordPress theme and environment. Here are some things to look out for –
1. The ‘Search API Plugin’ installs 3 different plugins.
To use Google Search make sure that the Search API Plugin and the Google Search Plugin are both activated.
If you get a ‘You do not have sufficient permission to access this page’ error message while trying to Edit Search Settings, then chances are the Search API Plugin has not been activated.
2. Search results may not display properly.
If your theme is set to display post excerpts, it may not properly show the search results. This is because the Google Search Plugin keeps the search results within the post_content attribute of a temporary post object.
To fix this, you may need to make some changes to your theme index.php file so that it uses the_content to show the search results instead of the_excerpt.
The Shiba Theme has been updated to properly show search results for the Google Search Plugin as of release 2.3.
3. Search results may not fill the page.
Depending on your theme, the search results may sometimes not fill the entire width of the page.
To fix this –
- Go into Plugins and Edit the Google Search Plugin.
- Select the search/google.php file on the right.
- Search for –
<style type="text/css" media="all"> #srchResult iframe { width: inherit; } </style>
Change width to the number of pixels that you want or to a percentage. 100% will use the entire space available. For example –
<style type="text/css" media="all"> #srchResult iframe { width: 100%; } </style>
4. Change Google AdSense advertisement location.
- Edit the Google Search Plugin.
- Select the search/google.php file on the right.
- Search for –
$_GET['cof'] = "FORID:10";
- Replace the “FORID:10” text with your chosen Google AdSense advertisement option.
- FORID:10 sets the Google AdSense advertisements to appear on the Top and Right.
- FORID:9 sets the Google AdSense advertisements to appear on the Right.
- FORID:11 sets the Google AdSense advertisements to appear on the Top and Bottom.
5. Search may no longer work in your WordPress dashboard.
The Google Search Plugin replaces all WordPress command line searches with a Google Search so your regular WordPress dashboard post, page, and media searches may no longer work.
To fix this,
- Edit the Google Search Plugin.
- Select the search/google.php file on the right.
- Search for –
function google_search()
- Add the line below to the beginning of the function –
if (is_admin()) return;
The result should look like this –
function google_search() { if (is_admin()) return; ...
If you are using caching for your WordPress blog, make sure not to cache your search results.
Congratulations! You Are Done.
You can test out the ‘Google Search Plugin’ by doing searches on this page or on the ShibaShake main page.