Google AdSense Search Results within WordPress Pages
Filed in: Adsense Tips, Make Money Online, WordPress — September 9th, 2006
As promised in my previous post, here is the instruction to having AdSense search results within WordPress Pages.
Wordpress Pages are like Posts, except they can do much more than Posts, and they live outside of the normal blog chronology. [Read more...]
What will we do?
- Generate new AdSense search code.
- Create a new Google Search WordPress Page template.
- Create a new Google Search WordPress Page.
- Insert AdSense search box code into WordPress template.
Step 1: Generate new AdSense search code
Generate AdSense for search code as usual, but tick "Open my results within my own site" at Opening of search results page under More options section.

Select "Open results within my own site"
The URL should be: http://www.YourDomain.com/google-search/
Note: You may change the "google-search" to anything else, but make sure you change the "Post slug" when creating a new WordPress Page for Google Search (Step 3).
Then, you will get two blocks of codes. The first part is search box code. The second part is search results code. Copy both of them.
Step 2: Create a new Google Search WordPress Page template
Now, we need to create a new WordPress Page template and insert search results code into it. In this example, I am using WordPress default theme (Kubrick).
- Create a new text file with your text editor.
- Copy and paste the following code into the new text file. The code creates a frame in the page to display Google search results.
PHP:
-
<?php
-
/*
-
Template Name: google search
-
*/
-
?>
-
-
<?php get_header(); ?>
-
-
<div id="content" class="widecolumn">
-
-
<!-- Google Search Result Snippet Begins -->
-
<div id="googleSearchUnitIframe"></div>
-
-
<script type="text/javascript">
-
var googleSearchIframeName = 'googleSearchUnitIframe';
-
var googleSearchFrameWidth = 700;
-
var googleSearchFrameHeight = 1500;
-
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 -->
-
-
</div>
-
-
<?php get_footer(); ?>
-
- Save the file as googlesearch.php
- Upload googlesearch.php into your WordPress theme folder, "default" folder in this example.
Note: If you are using other WordPress templates, you might need to edit page.php of the template, strip out WordPress code, and save as googlesearch.php.
Step 3: Create a new Google Search WordPress Page
Now, we need to create a new WordPress Page using the new WordPress Page template(googlesearch.php) to display Google search results.
- At WordPress admin, goto Write Page under Write.
- Type "Google Search" for the Page Title, but leave blank for the Page Content.

WordPress Page with blank content and "Google Search" as page title. - On the right, expand Page Template: and select "google search" (googlesearch.php).

- Make sure the Post slug is "google-search"
- Save the WordPress page.
Step 4: Insert AdSense search box code into WordPress template
Finally, replace your existing AdSense search box code on WordPress template files with the newly generated search box code in Step 1. Save your template files and upload to your server.
Congratulations!
You're done! You can test your on-site Google AdSense search and see the result at http://www.YourDomain.com/google-search/
Please let me know if you have any problem when implement Google AdSense search results within WordPress Page.
Of course, for those did it, please show us your Google Search WordPress page!
FAQ
Q: How do I hide the "Google Search" page from my page list?
A: You can hide certain WordPress page by using exclude argument in the wp_list_pages template tag. Please refer to "Exclude Pages from List".
Let me do it for you
Are you still blur and don't know how to do it? Hire me to do it for you.


