Lookie: a video from Inside AdSense! I went through a long list of difficult trial and error the other day, trying to get the new AdSense for Search results working in WordPress. After creating a static page, I posted this in another static page, and tried to get it to work.

Google
 
WebMacStansbury.com

Obviously, now it works, but I'd tried a different template, doing a lot of hacks, then thought I had it all correct. Then, I got an email from the AdSense team asking what I couldn't make work. In an effort to show how it didn't work, I found out that I was over-thinking the process. After creating the static page, WordPress adds breaks (the BR tag) to every line. While I was hammering away at trying to get that working, it dawned on me that I was working too hard at this, and I should've done the simplest thing first: created a template with the javascript code in it. Seeing the automatic line breaks in the source code of the page made me realize I needed to stick the javascript Google provides in the source of the page, not the story. I created this template, which you'll get if you search in the box above. It's reproduced here for your copy and pasting and stealing without attribution needs: <?php /* Template Name: Search Landing */ ?> <?php get_header(); ?> <div class="content"> <div class="primary"> <h2>Search Results</h2> <p><!-- Google Search Result Snippet Begins --> <div id="googleSearchUnitIframe"></div> <script type="text/javascript"> var googleSearchIframeName = 'googleSearchUnitIframe'; var googleSearchFrameWidth = 650; var googleSearchFrameHeight = 1300; var googleSearchFrameborder = 0 ; </script> <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"> </script> <!-- Google Search Result Snippet Ends --></p> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?> To use AdSense for Search on your site, follow these steps: 1. Most importunely, you need a Google AdSense account, and Google hands them out like candy, so don't worry about getting rejected. I'd put an affiliate link in here, but Google doesn't let me. DARN YOU GOOGLE AND YOUR DARNABLE MULTI-LINE JAVASCRIPTS!!! (Note: this is the desired behavior of WordPress and AdSense, that was just a little joke. Please don't cancel my account!) 2. Upload the template you just created to your template folder, and name it something like searchresults.php, it doesn't really matter. Just don't name it search.php, as that will overwrite the built-in WordPress search file. 3. Create a new static page you want the search results on. You'll need the name of this page when you create the AdSense for Search code, so make it memorable. Since it really isn't important to the overall operation of your site, don't name the page "Search." I'm not saying that it'll mess up anything, but it might conflict with the built-in search function, depending on your server. You can see what I've named my search results page. 4. Change the page template you uploaded to "Search Landing," or whatever you named it if you're being a maverick. On the right side of the page management screen, you'll see the "Page Tempate" box, and you change the drop-down menu to "Search Landing." If the template you uploaded doesn't show up in the list, then check to see if copied it correctly. The Search Landing template 5. If you haven't already, get the page you created and enter it in the AdSense setup. 6. Insert the search code in your sidebar template, wherever you want the search form. Test it to make sure everything's working correctly, then sit back and wait for the filthy lucre that comes with Google ads! Burn some hundred-dollar bills in anticipation. That's it, and your results should show up as normal. Next time, no thinking for me! Which, of course, would be normal. Comments? Questions? Ask me here. Look at the former frontpage image by clicking here. The original story with flawed tech is on page 2. Google now allows you to add AdSense for Search results on a page on your site. This is great idea, but it's a little difficult for the mentality of WordPress users. Like many others, I tried using a static page in the Write Page menu, and I added the code for the page results. SINCE CHANGED

Google
 
WebMacStansbury.com

Try a search with this menu. Those search result page will open as it's supposed to, and you'll see a ridiculously-long URL in your address bar, but you'll get no results. This is what led me to try and figure out where the conflict lies. When Google let users add AdSense for Search results on your own site, lots of people tried to install it. I was reading discussions over at blogHelper and ProBlogger about how they couldn't get it to work. Loving a challenge, I took to figure out how to do this. My results were mildly discouraging, but I did get it to work, just not how I hope Google will leave it. You need to create a new page named "Search Results," or something similar, then put this code in your sidebar or wherever you decide. Set up the search to point to the page your created. After you put the Search code where you want it, do a search for anything. The result page you get will have no results. For some reason, any header javascripts interfere with the Search code. How to work around this is to create a new page template in your theme folder. The theme would start with this as the first line: <?php /* Template Name: Google Search */ ?> I've named mine "Google Search," but it's really up to you. You'll upload this to your theme folder in a moment, after you've titled the file googlesearch.php and saved it. Go to the search page you created (the one I named "Search Results"), and get the HTML for the page. You'll need to copy it and paste the actual code into your googlesearch.php file. Look through the code, and take out any javascripts in the section. Also take out any of the admin code, such as the one for editing the page. You'll need to take out any javascript-dependent elements from your page, as well. Save your googlesearch.php file, then upload it in the same folder as the theme you're using right now. Go into edit your search results page and change the Page Template to "Google Search" (or whatever you named the template). Save the page. If all goes well, and there's no interfering javascript, you'll get get the results I get. Test this below. ALSO CHANGED

Google
WebMacStansbury.com

The inspiration for this wasn't that I had some great knowledge of AdSense or javascript, but that I took a second to figure out what was going on, looking at the title. Also, any javascript not called in the header still works fine. I'm sure Google will figure this out soon. Hoping, in fact. ADDED: What I didn't expect when I wrote this, was for anyone to actually use the search results from this post. The search function from the built-in search for WordPress works just fine for me, but others will want that, or for Google search. If anybody got the idea to search for something on MacStansbury.com, say, the 'kittens' like in the graphic from the front page, you won't find much in the way of content. That's actually a good thing, as any search from that page to this page will add the related links from the site, powered by Landing sites 1.3. That's because it thinks (rightly so) that the results of the search are from Google. However, to the naked eye, it all appears that you've never left this domain. The effect of this is if you look at this page from here: It’s a kitten, on a laptop, you'll see the normal page. Do a search on 'kitten' in that search, and you'll get the same page, only with related posts. Maybe. Landing sites is a tad finicky with whatever I've done to this site.

status: published
lastmod: '2006-10-25T06:31:42.000Z'
author: John Stansbury
cms: wordpress
custom:
  podPressPostSpecific: 'a:6:{s:15:"itunes:subtitle";s:15:"##PostExcerpt##";s:14:"itunes:summary";s:15:"##PostExcerpt##";s:15:"itunes:keywords";s:17:"##WordPressCats##";s:13:"itunes:author";s:10:"##Global##";s:15:"itunes:explicit";s:7:"Default";s:12:"itunes:block";s:7:"Default";}'
  _utw_tags_0: 'a:8:{i:0;O:8:"stdClass":1:{s:3:"tag";s:7:"adsense";}i:1;O:8:"stdClass":1:{s:3:"tag";s:6:"coding";}i:2;O:8:"stdClass":1:{s:3:"tag";s:6:"design";}i:3;O:8:"stdClass":1:{s:3:"tag";s:5:"howto";}i:4;O:8:"stdClass":1:{s:3:"tag";s:6:"search";}i:5;O:8:"stdClass":1:{s:3:"tag";s:8:"template";}i:6;O:8:"stdClass":1:{s:3:"tag";s:5:"video";}i:7;O:8:"stdClass":1:{s:3:"tag";s:9:"wordpress";}}'
  similarterms: search page google results template adsense quot code wordpress javascript created site work named landing static working result script show
comments:
  - id: '45'
    author: Wordpress Plugin for Google Search // mightyhitter.com
    date: '2006-09-24T19:19:23.000Z'
    content: '[...] There are few articles that describe how Wordpress users can have an onsite Google search results to be displayed on their own blog. It can be fairly easy to do that with new pages and template, as featured by this excellent article at LiewCF and here. [...]'