How to add a Google Adsense Custom Search to your WordPress Blog

Knowledge Base on June 30th, 2010 No Comments

This post was originally published at LionVineyard.com on 2009/03/07

Recently I was faced with the task of adding a Google Adsense Custom Search to he blogs I am administering. I have searched around and there are quite a few explanations. However, in my opinion, they all have the steps wrong as the direct you to create your Google Adsense Custom Search first and then go your blog. I prefer to set up the names on my site and then go to Google.

The steps in my opinion:

  1. Create a new page in your WordPress Dashboard and give it a unique name [eg. custom-search]. Most probably you will not want it to be listed under your page menu so get the id of the page [the_id()] and disable its display with the wp_list_pages() parameters.
  2. Go to your Google Adsense acount and follow the steps to create your Custom Search. When asked for the path to display the results give the pathe of the page you created in step 1 [eg. http://yourdomain.com/custom-search].
  3. Get the scripts that Google gives you. Put the Search Box script where you want it to appear on your site. In my case I have it on the side bar on your right.
  4. The Results script is a bit more tricky. You will have to edit the page.php file of your theme and put a conditional statement to include the script. These should be within the while loop.
    <?php if (is_page('custom-search')){ ?>
     
     //YOUR RESULTS SCRIPT GOES HERE
     
    <?php   }; ?>



This should allow you to have a Google Adsense Custom Search on your WordPress Blog. Feel free to see it in action on the Playground.

No Responses to “How to add a Google Adsense Custom Search to your WordPress Blog”

Leave a Reply

We stop spam together!

RSS Feed
on facebook
@twitter
footer