| |

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?

  1. Generate new AdSense search code.
  2. Create a new Google Search WordPress Page template.
  3. Create a new Google Search WordPress Page.
  4. 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).

  1. Create a new text file with your text editor.
  2. 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]

  3. Save the file as googlesearch.php
  4. 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.

  1. At WordPress admin, goto Write Page under Write.
  2. Type “Google Search” for the Page Title, but leave blank for the Page Content.

    edit google search page
    WordPress Page with blank content and “Google Search” as page title.

  3. On the right, expand Page Template: and select “google search” (googlesearch.php).

    Select page template

  4. Make sure the Post slug is “google-search”

    google search post slug

  5. 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. :)

adsense, google, search, searchengine, tips, wordpress

Similar Posts

62 Comments

  1. @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.

  2. @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.

  3. 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?

  4. @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…

  5. 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!

  6. 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.

  7. 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

  8. 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?

  9. 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 :)

  10. 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

  11. 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.

  12. Excellent! Worked the first time. I just love to see a post with steps which works the first time. Thank you so much!

  13. 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

  14. 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

  15. Works like a charm.

    I guess it was the previous theme that caused me some trouble.

    Thank you Liew.

  16. 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.

  17. 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!

  18. 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!

  19. 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. :-)

  20. @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. :)

  21. 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.

  22. 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.

  23. 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.

  24. 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.

  25. 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!!

  26. I don’t have a “Page Template” widget on my wordpress control panel. i use WordPress 2.3.1

    How can I implement it?

  27. 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.

  28. 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.

  29. 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

  30. 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.

  31. 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/

Leave a Reply

Your email address will not be published. Required fields are marked *