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.

  1. Sign up for Google AdSense or Google Co-Op Custom Search Engine.
  2. 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).

    Google AdSense for Search Results in Site
    Google Co-Op CSE Results in Site
    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.

  3. 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.
  4. 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.)
  5. 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.

  6. Save the new page template for your WordPress theme. You can give it any name.
  7. 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.
  8. 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.
  9. On the Page Template at the side, choose Search Results Page (or whichever name you gave to the new template).

    Post Template and Post Slug

  10. Save and publish the page.
  11. Edit your template, and put in the search box code to anywhere you like the search box to appear.
  12. 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.


10 Responses to “Integrate and Display Google AdSense for Search and Co-Op Custom Search Engine Results in WordPress Blog Page Template”

  1. Javier F.
    January 26th, 2009 12:17
    10

    Very clear instructions. I succesfully integraded google search to my blog. Thanks, great work!

  2. JD (1to1million)
    November 9th, 2008 21:16
    9

    Real shame that the results page (SERP) is dumbed down and doesn’t even display the number of pages..

    Give you » Results 1-10

    but misses the » …of about __,___ for

  3. rafa
    October 2nd, 2008 17:28
    8

    Hi,
    I succeded in integrating the search into my blog. The problem is that search results are to wide for being displaied correctly. since I need my sidebars for navigation (don’t have page nav in header) i only have about 600 pix available for display width. the minimum display width given by google is 795pix. so it messes up my sidebar and search result display.
    any help?
    thanks

  4. Radio
    August 14th, 2008 22:49
    7

    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…

  5. Probando el nuevo Búsqueda Personalizada de Google - Primate Blog
    June 15th, 2008 19:02
    6

    [...] 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 [...]

  6. Wordpress Plugin Centre - Clean Wordpress Template - Integrate and Display Google AdSense for Search and Co-Op Custom
    June 12th, 2008 15:41
    5

    [...] 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 [...]

  7. ragin'Geek
    May 10th, 2008 14:55
    4

    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?

  8. get it from Boy!
    February 3rd, 2008 11:58
    3

    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

  9. jameswillisisthebest
    September 9th, 2007 04:37
    2

    This is my first post
    just saying HI

  10. NetBloke
    August 20th, 2007 05:26
    1

    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?

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

frame php google coop - integrate google adsense in custom application - "inline search results" google - costom disply google pase change - Custom Google Search Results in php - googleSearch Unit Iframe width change - host search result pages adsense search box - can a static page in wordpress has adsense - Adsense El Paso - result google adsense search - adsense search integrate in site - googleSearchUnitIframe background - google adsense width size customize - customizing google adsense search box - google adsense for search vs - wordpress blogs - adsense for search same line - custom google ads width - inline search box code - sample width google adsense - google ads integration - google adsense for search - how to display sites in google search results - javascript google adsense search custom - step to integrate the google checkout in my website - ads google - Embeded adsense search engine setup - adsense search engine officelive - Adsense for search in wordpress - customized search provider doesn't show suggestions - www.google.com - Integrate Adsense+google - google adsense seARCH search word doesn't display - "adsense for search" css - google.com - how to display adsense search result on blogspot blogger - how to incorporate google search engine in my website -