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.