Newly revised and updated for Fresh News 2.0!
I wanted to replace the WordPress search engine with the Google Custom Search Engine (CSE) for better results and to take advantage of Adsense for Search. While there are several CSE integration tutorials for WordPress and even a plugin, none specifically addressed Woo Themes. My efforts were further frustrated because the coding strategies outlined in the existing tutorials didn’t entirely work for me and the WordPress plugin failed to install with a PHP parse error.
My requirements for Google Custom Search are:
- Search box must appear in the same position as the default search box to the top right in the theme header.
- Due to the limited width of the FreshNews DIV element (block level container) in the header for the search box, the “Search” button needed to appear below the text input control instead of to the right.
- The side bar must not be displayed on the Google Search Results page, because Google takes the full page width (600 pixels) and the sidebar will overlay the search results.
Google Custom Search Engine Demo
Go to www.handymanhowto.com to see the Google Custom Search integration with Fresh News 2.0. The following illustrates the Google Custom Search box (red arrow):
and the Google Custom Search results page for the phrase “pvc pipe”:
Google does an excellent job of indexing and searching your site.
How to integrate Google Custom Search to Fresh News 2.0
- Go to http://www.google.com/coop/cse/ and register for an account. If you already have an Adsense account, login with those credentials.
- Create a New Search Engine.
- Under the “Look and Feel” tab, choose the first style with the watermark. Click on the following image for a larger view.
On the Code tab:
- choose the iframe option;
- specify a URL http://your_domain_name/search/
- place advertising on the Right.
Copy the “Search box code” and “Search results code”. The code samples for my site are:
Search box code
<style type="text/css">@import url(http://www.google.com/cse/api/branding.css);</style><div class="cse-branding-bottom" style="background-color:#000000;color:#FFFFFF"><div class="cse-branding-form"><form action="http://www.handymanhowto.com/search/" id="cse-search-box"><div><input type="hidden" name="cx" value="006667729864162168081:5u85mytsil8" /><input type="hidden" name="cof" value="FORID:9" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></div><div class="cse-branding-logo"><img src="http://www.google.com/images/poweredby_transparent/poweredby_000000.gif" alt="Google" /></div><div class="cse-branding-text">Custom Search</div></div>
Note the key value highlighted above in red will be different for your web site.
Search result code
<div id="cse-search-results"></div> <script type="text/javascript"> var googleSearchIframeName = "cse-search-results"; var googleSearchFormName = "cse-search-box"; var googleSearchFrameWidth = 600; var googleSearchDomain = "www.google.com"; var googleSearchPath = "/cse"; </script> <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
Click on the Make Money tab to link the Custom Search Engine (CSE) to your Adsense account. My CSE has already been linked with my Adsense account.
This tutorial is continued in Part 2.
Hope this helps,
Bob Jackson
Copyright © 2013 HandymanHowTo.com Reproduction strictly prohibited.







Great guide. Thank you very much.
A small tip: Could you perhaps put the code in the post as well? It’ll save us the trouble from going back and forth between the post and editing.
Thank you again :-)
Sure! I’ve revised the tutorial to:
1) Remove the Search menu item from the main menu. All searches should done via the new Google Custom Search control and not by the menu bar. By default, Woo Themes displays pages as menu items and clicking ‘Search’ on the menu bar simply displayed an empty page, confusing the visitor.
2) Added links to the modified header.php and page.php files.
Your welcome,
Bob Jackson, HandyManHowTo.com
Hello, you can tell me how to add a 300×250 adsense block in this template?
I use the Adsense Manager plugin by Martin Fitzpatrick. You can get it here http://wordpress.org/extend/plugins/adsense-manager/.
Regards
Bob Jackson
Thanks a looooooooot Bob! God Bless you!
Wow, excellent article. Thanks for writing it.
beautiful blog merciiiii
Bob, thanks so much for taking the time to put together such a detailed guide. I was truly stumped on how to properly implement custom search until I read your post.
- so cool !
- “To remove the Search page from the header menu, add the &exclude= to the wp_list_pages() function” : wow wow, thanks for your help !