[AUTOMATIQUE] Cet article a plus de 5 ans.
Il se peut donc que les informations qu'il fournit ne soient plus totalement exactes.

I transferred the rights of this plugin (in April, 2016). Please, follow the links below to visit the official documentation.

Plugin presentation   Documentation

logo

Want to use Adblock Notify modal box only in some pages? Since v1.1, the new an_prepare hook now makes it possible.

This hook steps in during the plugin parameters injection in the DOM. Settings are JSON serialized to be easily retrieved by Javascript, so we can filter the JSON after it has been generated. That way, we modify the settings used by the Javascript plugin functions with a simple regular expression (REGEX).

The following filter is really simple to use, you only have to paste it somewhere in your theme and specify the page(s) ID.

	function filter_an_prepare($content){
		//get current page ID outside the loop
		$pageId = get_queried_object_id();
		$pageList = array('123','1234'); //page ID list

		if(in_array($pageId,$pageList)){
	
			//CSS
			wp_enqueue_style('an_style');
		
			$content = preg_replace('/\"anOptionChoice\"\:\"(.?)\"/i', '"anOptionChoice":"2"', $content);
			$content =preg_replace('/\"anOptionCookie\"\:\"(.?)\"/i', '"anOptionCookie":"2"', $content);

		}
		return $content;
	}
	add_filter('an_prepare','filter_an_prepare');

You can also display the modal box on some page types only:

function filter_an_prepare($content){
 
        if( is_page() || is_single() ){
    
            //CSS
            wp_enqueue_style('an_style');
        
            $content = preg_replace('/\"anOptionChoice\"\:\"(.?)\"/i', '"anOptionChoice":"2"', $content);
            $content =preg_replace('/\"anOptionCookie\"\:\"(.?)\"/i', '"anOptionCookie":"2"', $content);
 
        }
        return $content;

    }
add_filter('an_prepare','filter_an_prepare');

Obviously, no matter which plugin options you choose, if you have disabled “Modal Box or Redirection”, the modal box will always appear in your pages.

If you’re not familiar with Adblock Notify click here for details 😉

 

Post written byBrice CAPOBIANCO

WordPress addict and self-taught. I love to learn and to create, then to share…
Founder of bweb.
Share this post