Turn Off Google Ads in WordPress If Admin

December 2nd, 2008

You’ve implemented Google Adsense in your WordPress blog. Now, you want to avoid accidentally clicking on an ad to avoid being penalized by Google.

If you’ve manually added Google Adsense to your WordPress theme, this article is for you. If you are using one of many Google Adsense Widgets, this article might be for you assuming you know how to modify an existing widget.

This article will give you an idea on how to add a simple PHP code in your template to suppress Google Ads if a user or an admin is logged in to WordPress.

We will use the “is_user_logged_in()” function to determine if a user or an admin is logged in to Wordpress. A simple “if” statement is employed to display or not display the ad.

Sample 1 – The format:


...
Place your Google Adsense code here ....
...

Sample 2 – With actual Google Adsense Code:





Place this code to every Google Adsense code in your template. To view the ads, simply logout of WordPress.

Post to Twitter Post to Plurk Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to MySpace Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: , , ,
Categories: Programming, WordPress

3 Responses to: Turn Off Google Ads in WordPress If Admin

  1. Don says:

    Hi, Ive got a couple of questions about your wordpress template that I started using (awesome) is it possible to talk directly I sen my email…Thanks

  2. Liz Dalmoro says:

    VRy interesting to read it :P :D

Comments are closed.