Skip to content

Instantly share code, notes, and snippets.

@wtmujeebu
Last active May 16, 2022 05:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtmujeebu/a6211941378345f980ad0201b70328cf to your computer and use it in GitHub Desktop.
Save wtmujeebu/a6211941378345f980ad0201b70328cf to your computer and use it in GitHub Desktop.
Show cookie banner with a delay using CookieYes GDPR cookie consent plugin
<?php // Do not copy this line
add_action('wp_footer', 'wt_cli_delay_cookie_banner', 10);
function wt_cli_delay_cookie_banner()
{
if (class_exists('Cookie_Law_Info')) {
?>
<script>
jQuery(function() {
var timeDelay = 3000; //Time in milli seconds, 1000 ms = 1 second.
CLI.bar_elm.hide();
if (CLI.settings.notify_animate_show) {
CLI.bar_elm.css('visibility', 'hidden');
}
setTimeout(function() {
if (!CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME)) {
if (CLI.settings.notify_animate_show) {
CLI.bar_elm.hide();
CLI.bar_elm.css('visibility', 'visible');
CLI.bar_elm.slideDown(CLI.settings.notify_animate_show);
} else {
CLI.bar_elm.show();
}
}
}, timeDelay);
jQuery(document).on('click', '.wt-cli-manage-consent-link, .cli_manage_current_consent', function() {
CLI.bar_elm.css('visibility', 'visible');
});
});
</script>
<?php
}
}
@mxcrml
Copy link

mxcrml commented May 15, 2022

Hi,

Thank you very much for this code snippet. You should mention that loading animation should be deactivated when using it.
Indeed, I just noticed that [wt_cli_manage_consent] button is not working when this code snippet is used while animation is activated for loading. Fortunately, everything works fine when animation is deactivated. :)

Just in case some people face the same issue.

Best regards,
MC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment