If you're using AdSense in your sidebar or header (two relatively popular spots in WordPress templates) you need to be aware that Google prohibits the placement of AdSense blocks on Error pages. If you're using a custom 404 page this can pose a problem. The trick here, of course, is that you want to make sure you keep your ads on every other page - but you don't want them appearing on your 404 pages.
Luckily WordPress has a series of "Conditional Tags" that can help you overcome this dilemma.
Feel free to browse through some of the tags before continuing here... they can be helpful in a number of different ways (many of which I'll discuss eventually). For our purposes here though, we're particularly interested in the "is_404()" function.
Basically, the "is_404()" function asks the WordPress engine if the page being loaded is the 404 Error page. If it is, then the function returns "true;" if it's not then the 404 Error page then the function returns "false."
Mix this with some PHP and we can setup a PHP conditional statement that will do the job.
<?php if (!is_404() ) { ?>
AdSense code goes here.
<?php } ?>
This block is quick and simple - it just tells the server to show the AdSense code only if the page is not using a 404. If you're using more than one company for advertising, and the second company allows ads on 404 pages, you can take it a step farther.
<?php if ( !( is_404() ) ) { >
AdSense code goes here
<?php } else { ?>
Code from other company
< } ?>
With this code you can keep the template profitable while still abiding by AdSense's TOS.
3 Responses to “AdSense and WordPress 404s”
-
July 20th, 2006 at 7:21 pm
[...] A while back I wrote a brief article, AdSense and WordPress 404s, which showed how to keep AdSense off your 404 error pages using WordPress’ built in conditional tags. [...]
- Return of the Whatzit » Blog Archive » Keep AdSense out of your Post Preview
-
August 2nd, 2006 at 5:20 am
that’s a great tip!
Should become tip 8 for my 7 AdSense tips for WordPress article :P
http://www.seo-portal.com/7-adsense-tips-for-wordpress/2006/08/02/
- SEO Portal



[...] Wordpress, the platform that Suck Free Sites is using, has a built-in feature called to help you handle this issue. If you can copy and paste, you can modify your template (such as your sidebar, etc.) to only include the ad if the page is not a 404. This is accomplished in PHP with an IF/ELSE statement. [...]
- Suck Free Sites » Tutorial: Blog templates and AdSense TOS