Anti-Adblock integration for WordPress with WPCode (Pop-Under and Autotag)
- Last updated on May 27, 2025 at 10:21 AM
This article explains how to integrate the Pop-Under and Autotag zone scripts for WordPress with the WPCode plugin to support the monetization of Adblock traffic.
It consists of two sections:
- Prerequisites to get started
- Anti-Adblock script integration for WordPress
Prerequisites to get started
Before getting started, please ensure:
- Your website has been verified in Adcash's publisher panel;
- You have created a zone for your website with the intended ad format with the "Supporting monetization of Adblock Traffic" option.
Refer to the article Anti-Adblock Integration for Pop-Under and Autotag zones for more details.
To integrate zone scripts into WordPress, you should:
1. Install the WPCode plugin
2. Integrate ad scripts into the website
Install WPCode plugin:
1. Go to your WordPress admin dashboard.
2. Click the Plugins tab > Add Plugin.
3. Click the Add Plugin button on top.
4. Search for the WPCode plugin using the search box.
5. Click Install Now. Once installed, click Activate.
Integrate the anti-adblock script into the website
1. Return to your dashboard > find the installed WPCode plugin on the list > click Code Snippets.
2. In the opened window, click Add New > Add Your Custom Code (New Snippet).
3. Select PHP Snippet from the bottom menu.
4. Add a title > copy and paste the script provided in the Adcash publisher's panel into the code box.
Please note
Replace the highlighted DESIRED_FORMAT_HERE and ZONE_ID_HERE (e.g., Pop, Autotag; 9999999).
function
enqueue_adcash_anti_adblock_lib_script() {
$cache_key
=
'adcash_anti_adblock_lib_script'
;
$cache_timeout
= 5 * MINUTE_IN_SECONDS;
// check if already in temporary cache in db
$script_content
= get_transient(
$cache_key
);
if
(
$script_content
=== false) {
$response
= wp_remote_get(
'
https://adbpage.com/adblock?v=3&format=js'
);
if
(is_wp_error(
$response
) || wp_remote_retrieve_response_code(
$response
) !== 200) {
error_log
(
'Failed to fetch adcash anti-adblock library script.'
);
return
;
}
$script_content
= wp_remote_retrieve_body(
$response
);
set_transient(
$cache_key
,
$script_content
,
$cache_timeout
);
}
// register and add inline script to head
wp_register_script(
'acsh-anti-abl-lib-script'
, false, [], null, false);
// attach script content to newly created handle
wp_add_inline_script(
'acsh-anti-abl-lib-script'
,
$script_content
);
// enqueues for loading. manages dependencies
wp_enqueue_script(
'acsh-anti-abl-lib-script'
);
}
add_action(
'wp_enqueue_scripts'
,
'enqueue_adcash_anti_adblock_lib_script'
);
function
enqueue_adcash_anti_adblock_aclib_ad_init_script() {
// add dependent on library initialization script to footer
wp_register_script(
'acsh-anti-abl-lib-ad-init-script'
, false, [
'acsh-anti-abl-lib-script'
], null, true);
wp_add_inline_script(
'acsh-anti-abl-lib-ad-init-script'
,
'if (window.aclib) { aclib.runDESIRED_FORMAT_HERE({ zoneId: "ZONE_ID_HERE" }); }'
);
wp_enqueue_script(
'acsh-anti-abl-lib-ad-init-script'
);
}
add_action(
'wp_enqueue_scripts'
,
'enqueue_adcash_anti_adblock_aclib_ad_init_script'
);
Example below (please note that the image does not entirely depict the code. For the full picture, see the code above):
5. Once the script is added, scroll down to the Insertion section.
Make sure Location is selected as "Site Wide Header."
6. Click Save Snippet in the top right corner.
Please note: The WPCode integration solution will NOT work if you are already using the Adcash WordPress plugin described in this article.
Please deactivate one of them to be able to use preferred solution.
Do not hesitate to get in touch with us for setup assistance. Use our support chat or reach out via contact@adcash.com.
If you prefer the monetization of Adblock Traffic, see the articles below: