Custom Modal

Note: Custom Modal is available only in PRO version.
You must have at least 5.1.0 version to use developer documentation.

From v5.1.0, You can now add your custom modal or message popup after ad block is detected.

To create a custom modal, Add below code to your theme’s functions.php file

First we will enable the custom modal setting. By default it is set to false. We will change this value using filter hook.

/**
 * Filter to enable the custom modal
 * 
 * @param boolean $enable
 */

add_filter( 'chpadb/custom_modal',  function($enable){ 
        return true; 
}); 

This will enable custom modal settings. Now all the default settings will be disabled.

Now, We have to set JavaScript callback function. This function will be called if after successfully checked adblock status.

/**
 * Filter to set custom modal callback
 * 
 * @param string $callback
 */
add_filter( 'chpadb/custom_modal/callback', function($callback){
	return 'chp_ads_block_callback';
});

Now, We will add our modal and set callback functions.

/**
 * Add code to footer
 * 
 * @param boolean $enable
 */

add_action('wp_footer', function(){
  
     echo'<script>
               function chp_ads_block_callback(enable)
               {
                   console.log(enable);
               }
      </script>';

});

You can placed your modal any where inside the page. Now you can control modal or message using above JavaScript function.

In the above function, We will get the adblock installed status.

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.