WordPress – How to display message to adblocker users


The following WordPress script can be used to display a message to users that are running adblocker software.

The script has been written for websites running Google Adsense advertisements and simply adds a message where the advertisements would have been displayed.

To install the code, add it to your theme’s functions.php file (anywhere after the opening <?php line).

Why use this code?

Advertisements play an important role in the internet eco-system. Without advertising many websites would not be able to fund their operational costs such as hosting, domain name and software such as your theme, plugins and any special developments.

I believe that people are drawn towards using adblockers because advertisements are becoming more annoying – advertisements that stop you from viewing content – for example popup ads or minute long video ads that stop you from watching your favourite cat video on YouTube or having too many or inappropriately placed advertisements on a web page.

Unlike the handful of adblocker notify plugins in the WordPress plugin directory this code is PASSIVE this code will not annoy or prevent access to the web page content. It simply informs the visitor of the importance of advertisements and asks them to whitelist your website in their adblocker.

The message is also dismissable – so it can be closed and never seen again by the user on the their browser (this is done using a cookie).

Does this voilate AdSense policies?

No. I have spoken with the AdSense team and confirmed that doing this does not voilate AdSense policies.

The important thing to note here is that we’re not modifying the AdSense code, we’re not providing any ‘false clicks’ and we’re not providing any ‘false impressions’.

Having troubles installing this code?

Download and install the plugin version of this code.

(note this is NOT offered through the WordPress plugin directory — updates cannot be provided automatically)

Download: https://www.itsupportguides.com/downloads/itsg-adblocker-prompt.zip


add_action('wp_footer', 'itsg_adblock_message');

function itsg_adblock_message() {
        jQuery(document).ready(function() {
            var dismiss_cookie_name = 'itsg_adblock_message_dismissed';
            var dismiss_cookie = dismiss_cookie_name + '=1; Max-age=315360000; path=/'; // 10 years (60*60*24*365*10)
                if (jQuery('.adsbygoogle').height() == 0 && document.cookie.indexOf(dismiss_cookie_name) == -1) {
                    jQuery('.adsbygoogle').css("display", "block");
                    jQuery('.adsbygoogle').after("<div class='adblock_wrapper'><span class='adblock_wrapper_close'>Close</span><h2>Adblocker detected</h2><p>It looks like you're using an adblocker to prevent advertisements from displaying.</p><p>This website uses advertisements to pay for hosting and other operational costs.</p><p><strong>We ask that you whitelist <?php echo $_SERVER['SERVER_NAME'] ?> in your adblocker to help keep the website running. Thanks!</strong></p></div>");
                var disclaimer_close = jQuery( '.adblock_wrapper_close' );
                disclaimer_close.click( function() {
                    jQuery( '.adblock_wrapper' ).hide();
                    document.cookie = dismiss_cookie;
        .adblock_wrapper {
            border: 3px dashed red;
            padding: 5%;
            text-align: center;
        .adblock_wrapper_close {
            float: right;
            cursor: pointer;
            font-weight: 800;
        .adblock_wrapper_close::after {
            content: "X";
            margin-left: 10px;


Tagged in

4 comments on “WordPress – How to display message to adblocker users

    1. Hey Ali,

      I’m 99% sure this doesn’t voilate adsense policies, or at least I can’t see how it would. But to be on the safe side I’ve emailed the adsense support team to confirm this. I’ll let you know what they say.

      So I take it that you’re not sure how to implement the script? Are you running a WordPress website? Most people would dump custom code like this in a file called ‘functions.php’ in the installed theme. Im not a fan of this approach, it soon gets messy and eventually when the theme updates or you replace it – you loose all your customisations ! (unless you backup, which many forget until it’s too late).

      I thought about putting this code on the WordPress plugin website, but I saw many very similar plugins and thought the community had enough options.

      I like simple code like above, plugins, particually plugins on the WordPress plugin website tend to get big and messy quick as people as for updates and customisations. I like clean and simple.

      What I can do for you though is create a simple plugin that just contains the code above. So if you use WordPress it would be as simple as installing it from a ZIP file.

    2. Hey – Just letting you know that I heard back from the adsense support team and this code does not voilate any adsense policies. The important points being we’re not modifying the adsense code, we’re not doing any ‘false clicks’ and we’re not running advertisements off page (i.e. ‘false impressions’).

Leave a Comment

Your email address will not be published. Required fields are marked *