How To Integrate AdSense For Search on Your WordPress Site

So you want to integrate AdSense for search in your WordPress blog. Here’s a detailed step by step tutorial. Just follow each step as explained and you’ll have the AdSense for search on your WordPress site.

If you are uncomfortable editing the template files, or if you feel that an expert should handle the integration, then you can hire me to integrate AdSense for search on your blog.

1. Login to your Adsense account and go to, AdSense Setup > Get Ads > AdSense for Search.

2. Click on the link that says Single Page. This will make it easier to customize your AdSense for search code as everything will be on a single page.

adsense for search on wordpress step 1 How To Integrate AdSense For Search on Your WordPress Site

3. For search type, keep the Only sites I select option selected.

4. In the Selected sites text box, enter you domain like this,

integrate adsense for search in wordpress How To Integrate AdSense For Search on Your WordPress Site

5. Leave the Optional Keywords box empty.

6. Keep the default values for More options and Search Box Options settings.

7. For search results styles, select the option that says, Open results within my own site. Then enter the URL http://www.yourwebsite.com/search.

adsense for search results page How To Integrate AdSense For Search on Your WordPress Site

Adjust the page width according to the width of your WordPress theme.

8. Keep default values for Ad Locations settings and color settings, agree to AdSense terms, enter a name for your AdSense seacrh engine and click on Submit and Get Code button.

Adsense will generate two code snippets for you. One which must be used to create a the search box, and another to display search results.

That’s it for the AdSense interface. Keep the codes page open as we will need both codes later.

9. Login to your WordPress blog and go to Appearance > Editor.

10. Find out the search box code of your theme. It will be either in searchform.php or header.php file. It will look something like this code,

<form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
<div><input type=textsize=18value=” ” name=”s” id=”s” />
<input type=”submit” id=”searchsubmit” value=”Search” class=”btn” />
</div>
</form>

Replace this code with the search box code (the first code snippet) you got from Adsense.

11. Now to display the AdSense for search results, you must create a custom search results template file. To do that login to your WordPress site via FTP and download the template file page.php from your theme’s folder, and add this code at the top of it,

<?php
/*
Template Name: Search Results
*/

?>

Save this file with the name search-results.php.

12. In search-results.php file, delete everything between the main content area of this file. For example, if you are integrating AdSense for search on the twentyten theme, delete all the code between <div id="content" role="main"> and its corresponding closing div, and paste the second code snippet from the Adsense in between.

13. Now upload search-results.php file in your theme folder.

14. Create a new page with the name Search, choose page template as Search Results,

adsense for search results page template How To Integrate AdSense For Search on Your WordPress Site

Now publish this page. Yes publish the empty page.

15. That’s it. Now try to search something in the newly integrated AdSense for search and you should see the results immediately on the search results page.

Please use the comments form below if you have any questions related to integrating adsense for search to your WordPress blog.

share on twitter

Comments

  1. Mohit Sharma says:

    Works really well! thanks a lot! :)

  2. Marek says:

    Hi, thanks, your tutorial works great, but how can i hide the search page in my top menu. Between home page, contact, about. etc. Thanks for your respond.

  3. rakesh kumar says:

    I am not able to locate search result template. only default template is visible . Do you have any idea what to do now.

  4. AgentWP says:

    @rakesh kumar

    If you don’t have a search template in your theme, then make a copy of index.php file and rename it to search.php.

Leave a Reply