09.09.2010 in Home > Internet > Adsense > WordPress by Namit Gupta

How not to Display Ads to the Logged-in User [WordPress]

When I write a post, I have a bad habit of previewing it multiple times before publishing, this results in multiple reloading of my blog page and these page contains Google Adsense ads which on each reload of page generates an ad impression.

Making multiple impressions from a same IP address will result in faulty impressions and Google might even penalize Adsense account for “click-fraud” and if worst-case scenario, I might accidentally click on my own ads. And these extra “ad impressions” will also change my CTR data.

But now I am using some coding tricks to not allow displaying of ads when I am logged into WordPress. If you have the same habit of loading your blogs pages multiple times, while writing a post or while doing some editing work in your blog’s theme, this post will help you in not making the faulty impressing by not displaying the ads while you or any user is logged in.

So how not to display ads when a user is logged into WordPress? Its simple just put your Adsense Ad unit code between the following lines of code.


<?php if(!is_user_logged_in()) { ?>

// Adsense Code

<?php } ?>

Wrapping the Adsense code in the above lines will not display ads to the logged in user.

How not to Display Sidebar Widget Ads to the logged in user?

PHP code is not allowed in sidebar widgets, but you can do the same with Widget Logic WordPress plugin. Follow the below steps:

1. Download and install the plugin.

2. Goto the widget where you have placed the Adsense code.

WordPress Widgets

3. and enter this code in the widget logic box at the bottom left corner as shown in the image above.

!is_user_logged_in()

4. Click on Save.

5. Now the sidebar ads will not be displayed when user is logged in.

These were some tricks I use to save my Adsense account from faulty impressions, if you have some other tricks or tips do share them in your comment.

Related: Implement Google Adsense Section Targeting in your WordPress Blog.

Related posts:

  1. Implement Google Adsense Section Targeting in your WordPress blog
  2. Manually implement Google Adsense Revenue Sharing in your WordPress Blog
  3. What is Google Adsense Section Targeting?
  4. Twittar: WordPress Plugin to Display Twitter Avatar in Comments
  5. Adding About the Author Box Below each Post in WordPress
  • http://social-catalog.com aatif@social-catalog

    Nice one this very useful , as a blogger we have to refresh many times and there is problem with adsense

    • http://www.theitechblog.com Namit Gupta

      Hey, Thanks for your comment Aatif :-)

      Faulty impressions can cause serious problems, also it alters Ads CTR which can affect your earnings.

  • http://urbanpeek.com Rashed

    very very useful, Thank you for sharing man

  • http://www.techvorm.com Paritosh

    Beautiful!
    Worked as I wanted it to :)
    Thanks for a wonderful share buddy..

    • http://www.theitechblog.com Namit Gupta

      You’re most welcome Paritosh! :)