Make Money Out Of Nothing: Add Google Adsense For Search To Your 404 Page
A 404 page is an error page that is displayed when somebody tries to go to a link on your website that doesn’t exist. This could occur when someone linking to your website or typing in his browser address bar mistypes a url, or maybe that page has been moved or deleted by you. Lost opportunity? Maybe. But definitely not, if you follow this advise. Many people don’t have a 404 page altogether, a few implement with an inane message like “Something went wrong”, a few will try to help out the seemingly lost user by giving a few navigation options linking to home page, archives or most popular posts, etc. Definitely the last option among these is quite good to retain the users, but we’ll go one step ahead and turn this into an extra source of cash.
Note: This is perfectly fine according to Google Adsense TOS.
What we’ll do is implment a search box (Adsense For Search) on the 404 error page, which will net us the following benefits:
Give the users a way to search for what they would have come looking for and hence retain them on your website.
Make money if they click on any ads that are shown by Adsense for search.
Now we’ll see how to do it for a wordpress blog as well as a static site.
How to implement google adsense for search for your blog:#
**Common step: **The first step for independent of what kind of site you have, is to sign up for Google Adsense Publisher Account. Once you have signed up, log on to your account and go to Adsense Setup -> Get Ads -> Adsense For Search. Customize the box according to your need. (Select the “Open search results in my website” option to make sure users remain on your site. And insert a url where you’d like to show the results. e.g. mine is http://tech.shantanugoel.com/search/ ). Once you are done, you will get two snippets of code. One for displaying the search box and another for displaying the search results. Lets call them “Adsense-For-Search-Box-Code” and “Adsense-For-Search-Results-Code”. We’ll use them below for our implmentation.
For a static site: A static site is one where you have static/hand-coded html pages (i.e., not generated by a server side language, e.g. PHP). This requires 3 steps now:
Step 1) Create a 404.html page that will contain your search box code and will be displayed in case of a 404 error. A simple sample implmentation would be a blank page that contains just the search box code. The contents of this page can be as shown below:
Step 2) Create a search-results.html page that will contain the search results (You need to enter http://>your-domain-name</search-result.html in the adsense settings for this). Here, also you can either create a blank html page with just the search results code added or mimic the look of your website. Possible Contents:
Step 3) Modify your .htaccess file to add the following line:
And you are done. For a wordpress site, read on:
For a WordPress based site/blog: For a wordpress based site, you don’t have to modify the .htaccess. The 3 steps you have to follow are as below:
Step 1) Create or modify your 404.php file (generally in your theme’s root directory, e.g. http:///wp-content/themes//404.php ) to include the adsense for search box code. e.g.:
<?php get_header(); ?>
<div id="content">
"Adsense-For-Search-Box-Code"
</div>
<?php get_footer(); ?></blockquote>
Step 2) Create a search-results.php file (generally in your theme’s root directory, e.g. http://<your-site-name>/wp-content/themes/<your-theme>/search-results.php
) to include the adsense for search results code. e.g.:
<?php
/*
Template Name: Google Adsense Search Results
*/
?>
<?php get_header(); ?>
<div id="content">
"Adsense-For-Search-Results-Code"
</div>
<?php get_footer(); ?></blockquote>
Step 3) Login to your WordPress dashboard, go to Write->Page. Create a new page with its url/slug being http:///search (e.g. http://tech.shantanugoel.com/search ) or whatever that you input in your adsense settings. Make sure you select the page template as “Google Adsense Search Results” as we had mentioned in the search-results.php file at the top. Save this page and you are done.
Now, try to go to any non-existent url on your site (You can try this with this blog also, appending any weird url after http://tech.shantanugoel.com/ ) and you will be presented with the nice adsense-for search box. Let me know if this helped you out or you find any shortcomings in this or have any of your own tips. Also let me know if you need my specific 404.php and search-results.php files.