Detect Adblock Users on a WordPress Blog

Posted: July 20th, 2009 | Author: jriggs | Filed under: wordpress | Tags: , | 6 Comments »

The following code allows you to display an alternate message for your advertisements to users who are using Adblock as well as most other modern online advertisement blocking applications.
adblockplus
In your blog’s root directory (folder containing the wp-addon, wp-content and wp-includes sub folders), create a file and name it “adframe.js”.

This name is crucial because most ad blockers will prevent files with this name from being accessed by the browser.  In the file you have just created insert the following code:

adblock = false;

Now go to where you have added the advertisements in your code.  For instance, if you’re running Google Ads, it would look something like this:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxx";

Just before “<script” add the following div tag:

<div class=”a”>

After the second “</script>” tag, add the closing div tag “</div>”

The last thing to do is add the javascript logic that decides if we should display the alternate message.  Add this just before the closing body “</body>” tag:

<script type="text/javascript">
<!--
 var adblock = true;
//-->
</script>
<script type="text/javascript" src="http://<your-blog-domain>/blog/adframe.js"></script>
<script type="text/javascript">
<!--
 if(adblock) {
 var allElements = document.getElementsByTagName('div');
 for (var i = 0; i < allElements.length; i++) {
 if (allElements[i].className == 'a') {
 allElements[i].innerHTML = 'Hello, you are blocking ads.';
 }
 }
 }
</script>

Be sure to replace “<your-blog-domain>” with your own as appropriate.

Users running ablocking software will see the following message ‘Hello, you are blocking ads’.  Of course you can substitute this message with anything you want, or even add some html.  I should note that this is a prickly issue with valid points for and against ‘blocking the blockers’.  I found an excellent example of the central arguement anonymous user “Headz” posted on another site.

>>It’s their connection. Their experience.

“You’re not entitled to your own person experience when visiting a website, anymore than when visiting a McDonald’s, or your local bank. If you walk into a McDonald’s, and there’s a huge annoying neon sign promoting some burger, you don’t have the right to tear it down to better accommodate your dining experience. It’s the restaurant owner’s prerogative to structure his business how he or she chooses, which may include big annoying signs. If you don’t like it, you have other dining options — Like the Burger King across the street.

If you don’t like that your favorite tech site is flooded with ads, then go somewhere else. You have other tech site options. It’s arrogant to think you have a right to tear someone’s business apart to better accommodate your personal experience. You wouldn’t do it at a McDonald’s, so I don’t understand how you feel justified doing it at a website.”

Of course, his argument fails to consider the differences between brick-and-mortars and electronic venues.  I’m not sure which side I’m on for this one, I’ve already flip-flopped twice.  Thanks to http://detect-ad-blocking-software.webconrad.com/ for the original code snippet.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Create Blank Page for WordPress Blog Using Your Theme Template
  2. The Most Useless Facebook Fan Page Ever
  3. Block Spammers by IP address in WordPress

6 Comments on “Detect Adblock Users on a WordPress Blog”

  1. 1 Detect Adblock Users on a Wordpress Blog « Domain Talk said at 10:08 pm on July 20th, 2009:

    [...] Go here to read the rest: Detect Adblock Users on a WordPress Blog [...]

  2. 2 Block Adblock said at 6:48 pm on July 22nd, 2009:

    It is possible to block Adblock using CSS and no scripts. Works by using Adblock to block your content. Tell your friends!

  3. 3 Block Adblock said at 6:50 pm on July 22nd, 2009:

    Oops forgot the link: http://www.block-adblock-plus.com

  4. 4 djStelios said at 3:54 pm on August 15th, 2009:

    You’re great! So simple and so functional.

    Because I don’t want adblocking users at all (you know… ads is the only way to pay the webhosting bills), I made a simple change and I’m redirecting the user at adblockplus.org.

    My simple act is saying “Take back the user. I don’t want to consume my precious bandwidth and system resources.” ;)

  5. 5 Stylish user said at 10:25 pm on August 30th, 2009:

    Some people don’t know there are many ways to get rid of ads (and it’s stupid forcing people watching them, if they won’t click on).

    I’m talking about Stylish. It’s not as easy as set up Adblock, but effective.

    And also you can get rid of captcha using another approach against spammers. Javascript and cookies can help filtering, since most robots don’t handle both.

    Have fun and good luck :)

  6. 6 Fauzul said at 9:15 pm on March 8th, 2010:

    thank you for the information. gonna implement it at my blog. i dont have much advertisments on my blog but the ones i do have i dont want them to be blocked.


Leave a Reply