Steps on directing Google AdSense search results to pages within WordPress pages.

* When quotes are used do not type them unless noted *

  1. Within Google AdSense, generate new “AdSense for search” code
    • When you go through the steps to setup AdSense for search on Google’s AdSense website, make sure you select “Open results within my own site”.
    • For the URL, enter http://yourdomain.net/search-google
    • After you finish selecting your options like color etc. you will finally be given the code to put onto your site. The top box is the code that has the search form, and the bottom box has the code for the page that will display the Google AdSense for search results. Copy this code to a temporary text file. You will need this code to be copied to PHP files. Or just minimize the browser so you can refer to the code later on.

  2. Now, create a PHP WordPress template file. This file will display the ‘Google AdSense for search” results.
    • Most likely you are using a WordPress theme template, so make a copy of the page.php and name it searchgoogle.php.
    • Open searchgoogle.php with an ANSI text editor like TextPad. Do not use applications like Word because it will add other hidden characters to the file. (Not good)
    • Open the temporary file, or maximize your browser that has the “Google AdSense for search” code and copy the code for “Your search results code”…. into searchgoogle.php. Note that there will be other WordPress “stuff’ in there, so you will need to remove all code and only use the formatting code.
    • Save your changes to searchgoogle.php and if applicable, copy this file back to your WordPress theme template folder.
  3. Next, you need to create the WordPress Page that will be used to reference your new template.
    • Login to your WordPress Blog and write a new page. Use the title “search google”
    • Do not write anything in the content box but instead for “Page Template” select “search google”
    • and for the post slug type “search-google”
    • publish your new WordPress page
  4. Now we need to hide the new page called “search google” so user’s will not see it. If a user manually selects this page on your website, white space will display since nothing was sent to Google’s to search engine. (Again, not good)
    • (This part is going to take some searching your PHP files since each website will be different)
    • Before editing any file, make sure you create a backup of any file you are going to edit just in case you make a mistake. (Coming from someone who made the mistake)
    • Edit the PHP file that calls the PHP function,
      wp_list_pages which lists your pages.
    • For example a site may have this function on a sidebar so one would edit sidebar.php. The function you are looking for is called wp_list_pages. Once you find were this function is in your PHP file, you will need to exclude your new WordPress page that you just created so users will not see it.
    • For example page 83 is being excluded: wp_list_pages(’exclude=83&sort_column=menu_order&title_li=’);
    • This will exclude page 83, which is the number of the WordPress page that is being used in this example. You can get this number by clicking on the google search page.
      See example: http://yourdomain.ord/index.php?p=83

    • Save you changes and publish to your WordPress theme folder.
  5. Finally, (*phew*) add the code that will display the Google AdSense for search form. This is where users enter in search terms and click search.
    • Again, open the temporary file, or maximize your browser that has the “Google AdSense for search” code and copy the code, “Your search box code” to where you want to display your new Google form. This could be your page.php etc. The “sky’s the limit” is the first thing that comes to mind for where you can to put the code for the form. :a)
  6. Congratulations! You now have a Google AdSense for search form on your blog. And when a user searches Google on your site, the results will stay on your website! (*YES!*)
Tags: ,
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

counter