Hiding Ads on Your Site
August 2, 2009 No CommentsI wanted to hide my ads. Well acutually just from myself. I read somewhere once about decreasing some risk of clicking your own Adsense ads. So I found this snip of code on the net:
if (!is_user_logged_in()) {
// Insert Adsense (or whatever) code here
}
Cool right…!? Wait a minute. That removes the ads for all users of my site. It would seem to me if someone is a subscriber to my site, I might want to target those individuals. They must be interested in what I have to offer and took the time to register at my site. I want them to see my ads… right?
This is what I came up with:
<?php
if ($current_user->user_level < 2){
?>
//add html code here.
<?php
}
?>
This will show ads to everybody below the Author user role. If you use html pasted into the function leave the ?> and <?php. If you use php to generate the code you should remove the ?> and <?php. For more information on User Levels, Roles and Capabilities check it out from the source. http://codex.wordpress.org/Roles_and_Capabilities
WordPress, general, themes