To use the solution described here you need to install BlockAlyzer in your WordPress blog. Visit the BlockAlyzer adblock counter main page to learn more about the plugin or directly install it from wordpress.org.
Send adblock users to another page
There are a lot of anti adblock stategies out there. Some are as nice as a small message to switch off your adblock plugin. Others are more radical and prevent you from reading content or forward adblock users to another site. I personally respect adblock users and would first think about the friendly message telling them how the usage of adblock reflects on my sites content by limiting the ressources I have to build them.
I was directly asked a multiple times how to forward an adblock user to another website. So, despite me never using this on my sites, I choose this example to show you how BlockAlyzer can help you to do almost anything after detecting an adblock user. Be also advised, that I don’t know what effects this might have for the Google bot and on your ranking.
So the most simple working code example would be the following:
UPDATE: BlockAlyzer uses a small timeout before checking for adblocker, so this also needs to be included in the code. See this gist for a full example of code you can include into your functions.php.
To redirect an adblock user to a different external page, just use this snippet.
This will send visitors with activated adblock to http://www.example.com/. Please don’t use this code to forward to an internal page of the same website. It might create an infinite loop.
Adblock action with PHP
The other possible way BlockAlyzer offers you to know if a visitor uses an ad filter on your site is with a constant set in PHP. This constant is called BA_ADBLOCK_ENABLED.
The most easy check is this one.
if ( defined('BA_ADBLOCK_ENABLED') && BA_ADBLOCK_ENABLED == true )<br /> echo "You are using adblock.";
You can use this code in a template file or the functions.php of your theme. Be aware that this might not work in plugins, if they are loaded before BlockAlyzer. See below for a solution for that.
Please also notice that I added a check for the constant. This might be helpful if you decide to disable the plugin one time and don’t want ugly error messages to be displayed.
Redirect adblock user with PHP code
To redirect a user with adblock in PHP this code needs to be implemented in the functions.php file of your theme and not any other template file, because the header() function cannot be called after the first output was sent to the browser.
if ( defined('BA_ADBLOCK_ENABLED') && BA_ADBLOCK_ENABLED == true )<br /> header( 'Location: http://www.example.com/' );
Check with Cookie before the plugin is loaded
if ($_COOKIE['BaAdBlock'] === 'enabled') die('You are using adblock.');
When adblock wasn’t detected, the cookie is set to “disabled”.
This is the basic implementation for an anti adblock stategy in WordPress. I am planing on developing such a feature in BlockAlyzer or as an additional plugin. Please subscribe to the newsletter if you are interested or write a comment to motivate me on this.