Integrate and Display Google AdSense for Search and Co-Op Custom Search Engine Results in WordPress Blog Page Template
Google AdSense for Search features the ability to let web publishers to open and display search results within the website itself. In other word, the results of a user search performed in Google AdSense for Search box will appear within a frame on a page from the site, so that rather the users need not to leave the publishers’ websites and being taken to Google, while still able to search for information with Google web search. Beside, Google AdSense for Search, Google Co-op also has Custom Search Engine that can be placed and integrated, together with the search results into website, and comes with more customization options such as search refinements, ads positioning, prioritize or limit sites to include in search results, change and modify the look and feel, collaboration with users, ability to create multiple search engine, make money with AdSense, and of course, ability to integrate into existing website and blog templates.
To integrate, incorporate, embed and display Google search results from Google AdSense for Search and Google Co-Op Custom Search Engine within the template and theme of WordPress blog, we use the similar steps that used to integrate and embed Amazon aStore into WordPress blog by using additional Page template. You can embed the search results code snippets on a new post if you want to display search results based on your WordPress theme’s Post template. However, as Post doesn’t allow you to select a unique custom template for a single post, you will have the same layout among all the post entries and search results. This is not advisable, as sidebar may take up a lot of space, and the theme’s Post template has contains AdSense ads itself or other customisation that will make the embedded search results appear odd. So using a new Page template is better choice, and the Google search results can be made display on WordPress itself without any need of plugin.
To embed, integrate and display Google search displays from Google AdSense for Search and Google Co-Op Custom Search Engine in WordPress blog, try the following steps.
- Sign up for Google AdSense or Google Co-Op Custom Search Engine.
- When generate the Google AdSense search box code or Google Co-Op Custom Search Engine (CSE) search box code, remember to select “Open results within my own site” (Google AdSense for Search under Opening of search results page section) or “Host a search box and search results on your own site” (CSE under Add this search engine to your website section).
Key in the URL of the page on your site that the search results will appear. For WordPress page without page parent, the URL should look like this: http://www.yourdomain.com/page-title/ (i.e. http://www.mydigitallife.info/google-search/). Note: trailing slash is insignificant, and can be dropped. - You can do any other customization of your personal Google search engine, such as color, logo, style, layout, language, Google domain’s country, sites to include, and etc. However, it’s out of the scope of this article.
- After customizing the search box, generate and get the search box code and search results code. (You must have both code, if not your configuration of search box is wrong.)
- Create a custom page template for Wordpress based on your existing Page template. You may retain or drop the sidebar (<?php get_sidebar(); ?> line), as sidebar may take up a lot of your webpage space. If so you will need to adjust the width of search results accordingly during configuration and customisation of search box. Beside, as Wordpress templates are heavily aligned and positioned by using CSS DIV tags, you may need to remove DIV in CSS layout that restrict the width (if you remove the sidebar) or modify the structure of the layout in your Google search results page template. Generally, a Google Search search results page template without sidebar would like similarly like this (comments on template code in italic, can be safely ignored):
<?php
/*
Template Name: Search Results Page
*/
?>
The above section is important so that Wordpress will identify the new theme’s php file as a Page template. You can change the template name though.<?php get_header(); ?>
In Wordpress theme’s header, there may be also DIV tag that controls the width in the Page layout. If it’s the case, the remove this line, the copy and paste the everything from Header template, and modify accordingly.<div class=”content”>
Again, this may restrict the width of layout, if so, replace it with your own DIV structure, or simply with <center></center> (which I used) or just remove the line.<!– Google Search Result Snippet Begins –>
<div id=”googleSearchUnitIframe”></div><script type=”text/javascript”>
var googleSearchIframeName = ‘googleSearchUnitIframe’;
var googleSearchFrameWidth = 700;
var googleSearchFrameborder = 0 ;
var googleSearchDomain = ‘www.google.com’;
</script>
<script type=”text/javascript”
src=”http://www.google.com/afsonline/show_afs_search.js”>
</script>
<!– Google Search Result Snippet Ends –>Replace above line with your own Google search results code (not Google search box code).
</div>
If you don’t use any DIV above, just remove this line too. If you use <center>, replace with </center>.<?php get_footer(); ?>
Note: You can also exclude the theme’s header and footer (basically mean empty template file just just a line of search results code, which will display only search results, but that defeat the purpose of integration with Wordpress.
- Save the new page template for your WordPress theme. You can give it any name.
- Upload the new page template with search results code to your Wordpress theme’s directory. So if you’re using Blogsome or Wordpress.com, you may be out of luck.
- Create a new Wordpress static Page by clicking on “Write” then “Write Page”.
Key in Title as what you enter for URL to display search results during setup of Google search box above (e.g if you enter /google-search/ as URL for search results page, you will need to enter Google Search as page title). You page-slug has to be exactly the same with the URL entered as shown in image below. - On the Page Template at the side, choose Search Results Page (or whichever name you gave to the new template).
- Save and publish the page.
- Edit your template, and put in the search box code to anywhere you like the search box to appear.
- The search results from Google is now integrated with WordPress blog. Whenever a user search with the Google search box from AdSense or Custom Search Engine, the search results will appear within your WordPress blog.
For sample of integration and inline search results display in WordPress blog by Google AdSense for search, simply use the search box on top. For Google Co-Op Custom Search Engine, check out Google Medical Search Engine.
Share and contribute or get technical support and help at My Digital Life Forums.
Related Articles
- Which Search Engine is the Best and Most Relevant?
- Technorati Incoming Links Plugin for WordPress
- Force Firefox to Open Search Box Originated Result Page in New Blank Tab
- Windows Live Search Review by PC World
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working
- Add NoFollow Relationship to WordPress Blogroll to Increase PageRank
- Check Web Page Strength In Term of Search Engine Optimization
- Kosmix Search Engine
- Replace Google Blog Search with Technorati for Incoming Links in Dashboard of WordPress
- StatTraq - Wordpress Plugin for Site Statistic and Traffic Counter

































August 20th, 2007 05:26
I am trying to follow these instructions and am not having any luck with getting the results to appear on the search page.
I think I am not doing the static page bit right. How do I make it a static page exactly?
September 9th, 2007 04:37
This is my first post
just saying HI
February 3rd, 2008 11:58
i really like your ad layouts and of course on how to implement it in wordpress.org sites..
i hope you make them into wodpress plugins instead so that it will be easier. I’m pretty sure your site will be more popular.
thanks
May 10th, 2008 14:55
Is there a way to keep a published page from showing up? My template uses wp_list_pages to display the top level pages in a menu, can i suppress my search results page?
June 12th, 2008 15:41
[...] Integrate and Display Google AdSense for Search and Co-Op Custom To integrate, incorporate, embed and display Google search results from Google AdSense for Search and Google Co-Op Custom Search Engine within the template and theme of WordPress [...]
June 15th, 2008 19:02
[...] cierto, y más allá del nuevo producto Google, recomiendo este pequeño paso a paso que me vino muy bien para poder integrar los resultados en el template de [...]
August 14th, 2008 22:49
Buen artículo aunque las imágenes un poco borrosas. Llevo semanas intentando embedir Adsense en el blog de mi web sin éxito, a ver si siguiendo esta técnica…