Easy Cookie Law Update v2.3

I have just uploaded the version 2.3 of Easy Cookie Law WordPress plugin. The update comes with two major features:

Google Tag Manager

If you want to use Google Tag Manager in your WordPress website, you can easily insert the tracking code on the plugin options page. This will not only insert the code on your site but block it until the user accepts the use of cookies.

There is however a manual action required if you also want to show de <noscript> version of the code on the body. You will have to put a PHP line of code in your theme, just after the HTML <body> tag:

<?php if(function_exists('ecl_print_body')) ecl_print_body(); ?>;

If you want to put the tracking code just after the opening of the <body> tag as Google recommends, there is also an option:

First, you also have to manually put this other PHP line in your theme (normally in the header.php) there where you want to have the code, also, after the opening of the the <body> tag:

<?php if(function_exists('ecl_print_all')) ecl_print_all(); ?>

Second, select the option “Let me manually print the GMT code for the header where I want”. With this option selected, the code will be echoed via the PHP line you just inserted in your theme and not via the wp_head action hook as it normally is.

Helper functions

There are another two functions that you can use in your theme to detect if the use of cookies has been accepted.

One of the functions work with JavaScript and it is called ecl_is_cookie_accepted(). You can call it whenever you want like this:

      .. your JS Code here ..

The same function is available in PHP. But take care, it may not work depending on which cache plugin you are using in case you are using any:

<?php if(function_exists('ecl_is_cookie_accepted') && ecl_is_cookie_accepted()): ?>
    .. your JS Code here ..
<?php endif; ?>

In the next days, I will be extending the functions to make it compatible with other plugins and scripts.

If you have any question or proposal, do not hesitate to contact me!

Follow me on Twitter: @asanchezdev