Google Adsense Search integration in to Wordpress

When you look @ the normal search result page provided by adsense search it a blank page with just the results and it does not feel like its a part of your site. We can actually fix this and show the search result in a WordPress page so it looks like its a part of your site.

WARNING : Dont forget to backup any files before tou edit them !!

Lets quickly check the advantages of using Adsense search on your blog.

  1. In the long run you will find that when you have a lot of content on your site google search result will be better to find what you are looking for.
  2. With WordPress search you can only search within your blog, but you can define a list of sites to search when you use Adsense search.
  3. Monetize the traffic that searches for content on your site.

Step 1 : Create a new WP page

Now lets see how its done. First you have to create a page in WP where the result has to be displayed. I created a page called Search , you can name it what ever you want. Once created copy the URL for that page you will need it later in this tutorial. Mine was ” http://www.saijogeorge.com/search “

Step 2 : Create the Adsense for Search Ad unit

Now jump in to Adsense and create a new Adsense for Search ad unit.
adsense setup

On next page, select Only sites I select on Search Type, I wouldn’t recommend selecting The entire web. Now type in the URLs (one per line) of the sites you want to search in the Selected Sites section. If you want you can add keywords that matches your site content in the optional keywords area. You can leave the More Options area as it is and proceed to next step or make necessary changes in there like adding a custom channel for search.

The next step is customizing the Look and Feel of the search box, for me I just left the default settings on for this step.

Next in the “Opening of search results page” section select Open results within my own site and enter the URL of the new page you created before. Enter the width of results area according to the width of your main content area. If the main content area is less than 800px you cannot have ads on the right, so go for the ads on “Top and Bottom”. You can find the width of the main content area in the style.css file inside your theme directory. Most of the theme will have the width specified in contentleft . So open up the Design -> Theme Editor from the WP admin and click on style.css search for contentleft . Mine looked like this, and the width was 650px.
#contentleft {
float:left;
margin:0;
overflow:hidden;
padding:0;
width:650px;
}

setup adsense

Once all that is done go to the next screen , It will ask you to give the search a name then submit it to get the search code. You will be given two codes, a Search Box Code and the other one for the Search Result. You will need these later in this tutorial so save both those codes.

Step 3 : Adding the Search Results Code to your Search Page

Now its time to edit the Search page that we created in step one and add the Search Results Code in the content of the page and note down the post number as shown in the image mine was 62

Step 4 : Adding the Search Box Code to your WP Theme file

Now we add the search box on to the site. I have it in my header.php but depending on the theme used on the site it may be in the sidebar.php or even as a widget on the sidebar. You can use CSS to integrate it to go well with the theme you have on your site.

Step 5 : Remove link to Search Page from header


We dont want the search page to be shown as a link on the header of your site. By default most theme use wp_list_pages function to show the navigation buttons in the header, so all pages created will be shown. Now we look @ how to get rid of the link to the search page. Open the header.php and look for wp_list_pages . I had to change mine to so by including the argument exclude=62 we prevent the search page from being shown on the header.
Check the WP Codex for more info : http://codex.wordpress.org/Template_Tags/wp_list_pages

Step 6 : Keep Google happy

Many of us would have added Adsense ads on the sidebar but according to the Adsense T&C we should NOT add Adsense Ad unit to the search result page. So we have to get rid of the Adsense ads from the sidebar on the search page. We can use the is_page function to achieve this
if (is_page('62')) {
Any thing But ADSENSE ADS
}
else {
ADSENSE AD Code
}
?>

Check the WP Codex for more info : http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

Stumble
Delicious
Technorati
Twitter
Facebook

There Are 16 Responses So Far. »

  1. That last part is not working for me, can you explain more on how to omit the sidebar ads on the search results page?

  2. Hi digerati , looks like you figured it out. I can see that the sidebar ads are not shown on the search page on your site.

  3. can your show me the php code integrade with wp search …!
    please

  4. Hi kiwi freelancer

    for which part ? the search box integration on the site ?

  5. You say, “note down the post number as shown in the image mine was 62″

    but you don’t say what to do with it.

  6. I would appreciate any advice you have. I created a page called “Results” and I viewed that url and used it in my cse setup. I used the code for the search field and have put it successfully on the sidebar and on a page (I thought maybe the location was causing a problem.) When I do a search, however, the Results page (the page I created in WP) never opens. It just goes back to the first blog post. (I’m working on a new blog, which is primarily a custom search of sewing blogs.) I’d be so grateful for your help.

  7. Hi Kristin

    In Step 5 and 6 we use that number, thats to avoid the link to the search page in the navigation bar and to avoid adsense on the search result page ( if you adsense banners )

    So you have created a page called Result,, make sure you have setup adsense to open the result in the new page on your blog.
    Adsense will generate 2 codes put the search result code in to this page. Put the search box code in your sidebar.php or header.php depending on where you want it.

    Clear your cache and refresh the page, now your search result should open up in the new page.

  8. Still having issues removing the sidebar ads. Do we hard code that into the page.php template? Or sidebar.php template?

  9. To remove the ads on the side bar , you have to edit the file sidebar.php

  10. i am just starting out with Google Adsense. i am hoping that i would earn a good deal of money on this program.

  11. i am a beginner in monetizing my blog with Adsense. i still need to learn more about the tips and tricks on Adsense. hopefully i might be able to earn a decent amount of cash on Adsense.

  12. i really love Google Adsense. i could earn a decent amount of cash with this make money online program from Google.

  13. Our blogs share a lot in common. We should link to each other.

  14. Monetizing websites, blogs, etc is a good way to earn some passive income.;.’

  15. you can easily earn lots of dollars from adsense if you have a high traffic site.;,*

  16. monetizing a website is really a great way to earn money in a passive way just like real estate..;`

Post a Response