Disabling AdSense for Frequent Wordpress Visitors
Nov 23rd, 2006 by Alex
A quick bit of site news. I use AdSense, but didn’t want to inflate my page impressions when I’m doing work on the blog. After failing to find a Wordpress plugin to do this, I found a bit of inspiration to do it myself. My code varies slightly from that in the linked entry. In header.php, I inserted the following code where I wanted the AdSense ads to be displayed.
<?php
global $cookiehash;
if ((!isset($_COOKIE['comment_author_'.$cookiehash])) or (!is_user_logged_in())) {
?>
Adsense code goes here.
<?php } ?>
If the viewer hasn’t commented or isn’t logged in, they see ads. For regular visitors and logged in users, ads don’t appear. Simple, and a way of saying thanks to those who contribute their thoughts.