Hiding Adsense from logged in users

It’s not secret, I have Google’s AdSense on my site. What, a guy has gotta make a buck. The issue is, your stats will look really misleading in the AdSense interface because every time you view the site, you’ll get an impression logged of your ads. Currently I am using the ‘AdSense Manager‘ plugin by Mutube to manage and show my ads, as well as my ‘Better AdSense Targeting‘ plugin to help dial in the ad accuracy. With 2 lines of code, we can only show ads to non-logged in users. This means that you won’t be shown your own ads when logged in.

Hiding Adsense from logged in users

Once you have the plugin installed and running, you will need to edit 1 file it is located at:


Head down to line 222 and you will see this function: for the IF statement

01 function filter_ad_callback($matches){
02   global $_adsensem;
03   if($matches[1]==''){ /* default ad */ $matches[1]=$_adsensem['default-ad']; }
04   if(isset($_adsensem['ads'][$matches[1]])){
05     $ad=$_adsensem['ads'][$matches[1]];
06     if($ad->show_ad_here()){
07       return $ad->get_ad();
08     }
09   }
10   return '';
11 }

This is the function that shows your ads. So what we need to do here is filter out logged in users. We can do this with a function from WordPress called ‘is_user_logged_in()’. This function simply returns ‘true’ or ‘false’. So, we’ll make 2 edits.

01 function filter_ad_callback($matches){
02   global $_adsensem;
03   if (!is_user_logged_in()) { // Added logged in check
04     if($matches[1]==''){ /* default ad */ $matches[1]=$_adsensem['default-ad']; }
05     if(isset($_adsensem['ads'][$matches[1]])){
06       $ad=$_adsensem['ads'][$matches[1]];
07       if($ad->show_ad_here()){
08         return $ad->get_ad();
09       }
10     }
11   } // Close the new bracket
12   return '';
13 }

And there you have it, your plugin no longer shows AdSense Ads to logged in users. Now, any upgrade of this plugin WILL break this. I was hoping to find a hook or something in order to allow me to extend this plugin, but alas, there is nothing. I’ll be contacting the developer to hopefully get this added in the future.…

Better AdSense Targeting

Better AdSense Targeting

About the “Better Adsense Targeting”:

This is a WordPress Plugin that will allow you to choose which sections of your page Google’s Adsense service will use when determining what ads to display, allowing more relevant ads to display based off your content. The included shortags [ignore] and [/ignore] allow you to have content within your post or page ignored as well.


This is tested on the most recent version of WordPress. The minimum for this plugin is WordPress 2.7.1.

To install this plugin within WordPress

  1. Login to your WordPress admin area
  2. From the Plugins menu choose “Add New”
  3. Search for ‘better adsense targeting’
  4. Verify that it’s the ‘Better Adsense Targeting’ plugin and click ‘Install’
  5. You should now have ‘AdSense Targeting’ as an option in the Settings menu, go there and set up the plugin to your liking.

To install this plugin manually:

  1. Download the .zip archive
  2. Unzip and upload the “better-adsense-targeting” folder to your “wp-content/plugins/” directory
  3. Then simply Activate the Plugin
  4. Use the ‘AdSense Targeting menu option to configure your settings.

Better AdSense Targeting

Taken from the Google Section Targeting page:

You can use section targeting to make suggestions about as many sections of a page as you like. However, please be aware that we can’t guarantee results, and that it may take up to 2 weeks before our crawlers take into account any changes you’ve made to your website, you can learn more about website design at http://www.chriskdesigns.com/basic-web-design-facts-2020/

In order to properly implement this feature, you’ll need to include a significant amount of content within the section targeting tags. Including insufficient content may result in less relevant ads or PSAs. In addition, please keep in mind that this feature should only be used to emphasize significant sections of your site’s relevant content. It is against our program policies to manipulate the ad targeting to result in ads that are not relevant to the content of your pages.

Change Log:

-Version 1.1-

  • Corrected issue when the loop is entered in the sidebar
  • Am now using the Shortcode API for the and tags in posts
  • Removed option for Comments as there is not valid way to know the start/end of comments loop yet.
  • Added check for W3 Total Cache and warn to allow comments when minifying

-Version 1.0-

Added the ability to include ‘In-line’ ignore statements. If you wish for Google to ignore specific sections of your post just wrap it in the and tags.

-Version 0.1-

Initial release.

This post has been published with the help of web design Ireland, who test this plugin on there various websites, before putting this information live.…