We provide the code snippets and content on this page without any guarantee or support. In most cases, these pages are created on requests or based on individual solutions sent to us by other users. After it was published, we are only reviewing the code and content when we are made aware of an issue. Please let us know if you find one.
Please only use the codes if you understand them and know how to add custom code to your WordPress site.
If you’re comfortable with coding and want a custom solution to detect ad blockers and show alternative content, this approach is for you. If you prefer using a built-in solution, the ad blocker suite of Advanced Ads Pro will provide you with detection and many more countermeasure options—without touching any code.
To implement a manual solution, copy and paste the following code wherever you want the ad to appear. Use neutral class names, avoiding terms like “ad,” “banner,” or “sponsor,” which ad blockers might easily detect.
<div class="the_first_container">
<!-- your AdSense code goes here -->
</div>
<div class="the_second_container"></div>
<script type="text/javascript">
window.setTimeout(function() { // wait for ad blockers to do their thing
if ( jQuery( ".the_first_container" ).height() === 0 ) {
jQuery( ".the_second_container" ).html( '<a href="http://your_affiliate_link.com" target="_blank"><img src="your_new_image.jpg"></a>' );
}
}, 1000);
</script>
Code language: HTML, XML (xml)
The script checks the height of the ad container to detect if an ad blocker is active. If the container height is zero, it loads a static image with an affiliate link as an alternative. This image is treated like any other content image, making it unlikely to be blocked.
This manual solution is excellent for those who enjoy coding and don’t have access to Advanced Ads Pro.