Google AdSense Search Results within WordPress Pages
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…]
Table of Contents
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(); ?>
< ?php get_footer(); ?>[/php]
- 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. :)
nice post you have there. i will try to implement them later. ;)
Thanks Liew, very useful post. Hope if I can increase my earnings from google adsense.
May i know what is the purpose of “Make sure the Post slug is “google-search”?
Thanks for your explanation!
@ahwong5: the “post slug” is related to the URL in Step 1, BOTH need to be the SAME.
Since we use “google-search” in Step 1, then we need to make sure we are using “google-search” as post slug in Step 3, too.
Great tutorial,
cheers
I can’t search on your site with Adblock Plus Firefox extension enabled. You have to do something about this as many people use this extension
@John TP: Well, the Google AdSense code is not under my control. You might need to unblock Google AdSense in AdBlock Plus for it to work.
yaya… adblock almost blocks all adsense…
TQ for the info…i will try it at home tonite
Check out my on site search:
http://www.worldcupcorner.com/search/
I must tweak the design more…
Hey,
Thanks for the helpful post. One question – what’s with the big white space that shows up after the search results. Anything that we can do about that?
@worldcupcorner: nice color theme, look like part of your site. :)
@fiLi: the AdSense search result page’s default height is 1500px (googleSearchFrameHeight = 1500). I don’t think we can modify the code…
Hi – just wanted to thank you very much for providing this. It worked first time – and I’ve been trying to do it (using other people’s advice) for days and days. Brilliant! Shame it looks so crap and we can’t change the height or width of the frame (well, I can’t). Cheers!
It is easy to change the width and height of the frame… but I don’t think Google allows us to do so. According to Google AdSense program policy: NO code modification.
Altering the code in the obvious places doesn’t help. It seems that the place is reserved for ads on top of the search.
nice post you have here. I will try and wrote my comment here later.. :P
I discovered this when they first introduced this, but I’m not sure how to make it. Thanks for the tutorial.
nice..its really work!
Thanks. Your instructions were very useful.
Hi…
I’ve implemented it to my site!
After 3 hours working on it, try this, try that, finally it matches my template and looks good! but the search result is kinda lame…
Please visit my site to check it out!
Thanks
Man sometimes I feel like a WP-noob.
I’ve done exactly as written above but I can’t get it to work. I’ve add the search field at the bottom of my frontpage. (I’m going to move it up once I get it up and running). The problem is when I click the search button it takes me to a blank page. My blog is installed in a folder called blog, do I have to change anything?
Fantastic. It was easy following your instructions Liew. I got mine working in under 15 minutes. Also added headers for Google adsense and at the side too beside the results.
Not sure whether this was allowed or not but since I see you doing it, I guess it’s alright :)
Hello there,
I don’t understand how come it returns me with this line:
Fatal error: Call to undefined function: get_header() in /home/kenneth/public_html/wp-content/themes/flawless-imperfection/googlesearch.php on line 11
I would be grateful if you could help me out.
Regards,
Kenneth
@Kenneth: you should put the wordpress page’s URL in the adsense search, NOT the path of the googlesearch.php.
I’m sorry Liew, but could you elaborate more? I still do not understand. FYI, I put my googlesearch.php in /public_html/wp-content/themes/flawless-imperfection.
This is how I put it in my header (where I want the search box to appear):
….form method = †get †action = †http://mrdefinite.com/wp-conte…/flawless-imperfection/†target….
@Kenneth: you should put “http://mrdefinite.com/?page_id=577” as the search page URL, not the /wp-content/blahblah…
Liew, I have changed what you said, but what should I out in my post slug? Cos it still doesn’t seem to work..
Excellent! Worked the first time. I just love to see a post with steps which works the first time. Thank you so much!
Hi,
First of all, terrific instructions. I had it working right at the first try – though it took me a while to get the search box blend in into my template.. even now it looks kind of ugly – but that’s irrelevant. Those who still haven’t managed to figure it out are most welcome to drop by my site and ask for any kinda help needed on this.
My question is – when I create the search page, using the googlesearch.php template as you’ve shown – that page shows up in the horizontal top-menu as an item named “Google Search”. Any ideas how to get rid of this ??
Thanks,
m^e
Hello,
thanks for this helpful post. Just implemented my Google Search WordPress page on my blog.
Cheers,
Matt
very cool thanks. btw the next step is to exclude the ‘google search’ link from the navigation area. The solution is to use the exclude parameter as shown in the wp codex.
Thanks gary, for the tip – till now not knowing what to do, I’d commented out the wp_list_pages() function and was adding in links manually in the header, which of course was a bitch and a so totally inelegant way of doing so. Now all’s fine :)
Cheers,
m^e
Thanks a lot, this is a very helpful article.
Works like a charm.
I guess it was the previous theme that caused me some trouble.
Thank you Liew.
I get the following error when I try to view the page I created using the googlesearch page template:
Parse error: parse error, unexpected T_DNUMBERon line 9
Any ideas? Thanks for your help.
How came that if I try to search at the top of page, I get the Google page and not a site template? I was only trying to find an example of the plugin!
I’ve just started blogging in the last week and am finding myself stumbling along slowly with many things right now as I pick things up.
I spent hours trying to get my custom Google search page sorted, then found this site and had it sorted in 15mins, many thanks for a great step-by-step guide!
Great post…thanks! One question though, how come you don’t do this on your blog? I tried out your search but it’s not setup. :-)
@David: thanks for the remind. The on-site search was returning error after I upgraded WordPress to version 2.0. I will implement it again. :)
Hi Cheon Fong, thanks for the details! Now the search results page looks like it belongs to the site.
However the frame height variable doesn’t seem to have any effect on the page look – still a block of white space before the footer.
For some very weird reason. The search results in Firefox are blank, but it works fine in Opera and IE7. It says PHP: on the search result page.
Worked like a charm! Thanks!
Just yesterday I was trying to implement this feature into my blog. And then today I found your tutorial. Very helpful. I will try this today and test. Thanks a million.
This is an awesome tutorial, thank you much!!
Worked Perfect!
Also I was able to put the Search Code in the PHP file that way if the use wants to search again from the same page they can.
Thanks a lot for the very useful info. I’ve spent a few hours trying to figure out how to get the search results to show up on my page, and you’ve saved me from wasting any more time :) Works like a charm now.
Cheers!!
I had implemented this on my sci-tech news site, Sciencebase.com, months and months ago, but totally forgot how to do it to get started on my blogging tips site. Thanks for the timely reminder
Dave B
I don’t have a “Page Template” widget on my wordpress control panel. i use WordPress 2.3.1
How can I implement it?
Great tutorial. Worked first time.
Many thanks.
PP
Simple 3 step process. Excellent, I was searching for this. Now I can easily integrate customized Google search page on my blog.
Greats Liew. It works now.
Thanks a lot
Thx liew for this tip. now i can setup this search engine
Good work!
Hello Mate,
Thanks for your nice post, But i want to put adsense search box like your site in which user can select either Web or Site.
How can i put search box like you. Please help me.
and one problem is that my adsense search box is showing inactive. I dnt know why??
Have u any idea about that. Please help me.
Thanks in Advance.
Ankur Gandhi.
@Ankur Gandhi: the adsense box format that I use on this site is no longer available. it has been replaced with better adsense custom search. you can read more at https://www.google.com/adsense/support/bin/topic.py?topic=144
great post mate , you can actually take it one step further ans integrate the ads in to the page that you create on wordpress itself so it looks much more integrated on to the site. I have written a post about it on my site.
Thanks for this, it works perfectly.
Well, almonst. I just need to figure out a way to make it fit in with my theme.
Thanks again, I would never have thought of using a page tempate.
Dave
u have idea for adsense code integrade with wp searh…!
please help me
Just yesterday I was trying to implement this feature into my blog. And then today I found your tutorial. Very helpful. I will try this today and test. Thanks a million.
wow..thanks, i currently looking for this,, it’s really helpful
Thanks! Great article. Was just what i was trying to do, saved me heaps of time and stuffing around.
I’m using WP-Clear of solostream. everything is done as you said except step 3 “On the right, expand Page Template: and select “google search” (googlesearch.php).” I don’t see any page temp to select the file which has been uploaded. What should I do? Please reply fast or email me. You can see my problem @ http://englishpack.com/google-search-results/