Those who have Google Adsense account and WordPress may want to add Google Adsense Search function to his or her WordPress blog. Besides the search functionality from Google to search the pages within your site and Internet, you also can earn money from the Adsense advertisement within the Google Search result.
There are a few approaches you can add a Google Search function into your WordPress, but at here, I will show you the approach I am using and I think it is the easiest one.
Step 1 – Get Ready with Google Search code
Login to your Google Adsense account. Click on "Adsense Setup" and then "Adsense for Search". Apply your own style, and under "Opening of search result page", make sure you have chosen "Open results within my own site". Type in the page URL on your WordPress blog that you want to show the search result (e.g. www.snippetit.com/search) under the "Enter URL where search results will be displayed" and also type in the width on your web site that available for the search result. You should get two types of code from the "Adsense for Search" setup page, the "search box code" and the "search result code".
Step 2 – Install your "Search box code"
Copy the code under "search box code" and install the code into your web site. It is the code that display the search box. Put it to a place where user easily see and access (normally at the side bar). If you are using the newer version of WordPress, you can copy and paste the code into WordPress’ sidebar text widget.
Step 3 – Install your "Search result code"
Create a WordPress template page and name it as search-result.php (or whatever you like) and put the file in your theme folder. Include all the necessary coding into the php file (e.g. template name and necessary functions calling). Then copy and paste the "search result code" into the template. Generally, the content of search-result.php should look something similar to this:
<?php /* Template Name: Google Search Result */ ?> <?php get_header(); ?> <div id="content"> <!-- Google Search Result Snippet Begins --> ... <!-- Google Search Result Snippet Ends --> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Step 4 – Configure WordPress to show Google search result
Login your blog’s administration page, under "Write" and then "Pages", write a new page and make sure you choose the "Google Search Result" as the template. Give it a title and save it. Edit the saved page, make sure the permalink matches the URL you have keyed in in step 1. If not, modify it.
Step 5 – Test
Open your blog, you should now see the Google Search Box on your web site. Type in some keywords and hit enter. Your site should be redirected to the URL you have configure in step 1. If it redirect to the wrong page or you get and error, make sure you have done step 1 and step 4 correctly.
After that, check that the Google display the search result on you web site correctly. If it doesn’t show anything make sure you have done step 2 and 3 correctly or you can try reenter another keywords (something general).
And that’s all.
Leave a Reply