How to display an image banner if adblockers block adsense ad

Blocking ads using Ad blocking softwares or using browser extensions is growing at high speed. Adblock and Adblock plus etc are examples. Users may enjoy the website content without getting any popup ads or annoying ads, but it is a pain point for publishers who rely on Google adsense or other online website monetizing programs. When adsense ad is blocked by ad blockers, empty space will be displayed in that space.

As a website publisher, you can promote your site by displaying it’s content (an image or text) in place of blocked adsense ad or you can ask the audience to whitelist your site in Ad blocker settings or you can display Facebook like button or twitter widget etc.

Below are the steps

1. Copy the below code



window.onload =function(){


var ad = document.querySelector(“ins.adsbygoogle”);

if(ad && ad.innerHTML.replace(/\s/g,“”).length ==0){ =‘display:block !important’;

ad.innerHTML =‘Your custom HTML messages goes here’;


},2000);// The ad blocker check is performed 2 seconds (2000 ms) after the page load



2. Goto your blogger dashboard -> Layout

3. Click on Add a Gadget

4. Click HTML/JavaScript gadget

5. Paste the code into the above gadget content

6. If you want to replace the blocked adsense ad space with an image banner, replace

ad.innerHTML =‘Your custom HTML messages goes here’;


ad.innerHTML = ‘<a href=”Enter site link here” > <img src=”Enter image URL here” alt=”image description”  width = ” Enter width” height = ” Enter hieght of image” /></a>’;

Enter the image info in above line of the code and save the widget. See below example

ad.innerHTML = ‘<a href=”” ><img src=”” width=”300″ height=”250″ /></a>’;

7. You can replace the blocked ad space with a link, Facebook like button,twitter widget etc.


1. Only the first adsense ad on the site will be replaced with alternate content

2. It works only for Google adsense ads

3. You can also use above code in wordpress or any other platform

4. There is no violation of Adsense policy by doing above trick

Source: Amit agarwal-

About the Author


A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

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