This tutorial provides the steps to display a fixed cookie consent bar that can be dismissed by your site visitors at the bottom of your site.
Step 1
Go to https://cookieconsent.insites.com/download/, configure the cookie consent bar to your liking and you should see the generated code.
In this example, we shall go with the default one.
Step 2
Install and activate Code Snippets plugin.
Go to Snippets > Add New.
Title: Cookie Consent
Code:
add_action( 'wp_head', 'custom_cookie_consent' );
/**
* Add Cookie Consent bar.
*
* @link https://cookieconsent.insites.com/download/ Code generated from here.
*/
function custom_cookie_consent() { ?>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#000"
},
"button": {
"background": "#f1d600"
}
}
})});
</script>
<?php }
Replace the code above in between function custom_cookie_consent() { ?>
and <?php }
with the code generated in the earlier step.
Set it to run only on the front-end.
Save and activate.