Hi @sababaa,
Please try using below code snippet.
add_action('wp_head', 'cli_add_bar_class', 9);
function cli_add_bar_class() {
if (class_exists('Cookie_Law_Info_Public')) {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
if (jQuery('#cookie-law-info-bar:visible').length > 0) {
jQuery('#cookie-law-info-bar').addClass('cli-bar-active');
}
//remove class after consent
jQuery('.cli_action_button').click(function(e) {
e.preventDefault();
if (jQuery(this).attr('data-cli_action') == 'accept') {
jQuery('#cookie-law-info-bar').removeClass('cli-bar-active');
}
});
});
</script>
<?php
}
}
Hi,
The code do what i want, thank you!
Another question, when i want to detect if “cookie-law-info-bar” has class “cli-bar-active”, my js don’t work.
In console, this return false:
console.log(jQuery('#cookie-law-info-bar').hasClass('cli-bar-active'));
If i try another class, it’s return true:
console.log(jQuery('.bt-form-sticky').hasClass('bt-form-sticky'));
My full code :
$(document).ready(function() {
if (jQuery('#cookie-law-info-bar').hasClass('cli-bar-active')) {
jQuery('.bt-form-sticky').toggleClass('test');
}
});
Hi @sababaa,
Please share your site URL.
My website can’t be share before launching. It’s a private project, sorry.
No error in console, no cache system.
Some screenshot to help you :
https://i.gyazo.com/ff52c65fd87c6c0bf04603483afbc69a.png
https://i.gyazo.com/6e7578bc18d29a91a1832349183a8219.png
Hi,
Finally, with your code, i wroted something more easy :
add_action('wp_head', 'cli_add_bar_class', 9);
function cli_add_bar_class() {
if (class_exists('Cookie_Law_Info_Public')) {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
if (jQuery('.cli-bar-container:visible').length > 0) {
jQuery('.bt-form-sticky').addClass('test');
}
//remove class after consent
jQuery('.cli_action_button').click(function(e) {
e.preventDefault();
if (jQuery(this).attr('data-cli_action') == 'accept') {
jQuery('.bt-form-sticky').removeClass('test');
}
});
});
</script>
<?php
}
}
I’he just had my class “test” on the div who need to move.
Thank you.