Cookie Notice
A simple way to show the cookie notice on your website without overloading it. Lightweight (~1kb), quick setup and themes.
Setup
Internal installation (why?)
Styles: Add the following code to your HTML <head></head>
section.
<style>
#cookie-notice {
display: none;
position: fixed;
right: 0;
bottom: 0;
left: 0;
z-index: 999;
max-width: 450px;
margin: auto;
padding: 0.5rem;
border: 1px solid #eee;
background-color: #fefefe;
box-shadow: 0 0 0.25rem rgba(0, 0, 0, 0.05);
font-family: Arial, Helvetica, sans-serif;
line-height: 22px;
font-size: 15px;
text-align: center;
color: #555;
}
.cookie-notice-more {
margin: 0 0.25rem;
text-decoration-style: dashed;
color: inherit;
}
.cookie-notice-close {
padding: 0 0.5rem;
border: 1px solid #ddd;
border-radius: 0.125rem;
line-height: 20px;
text-decoration: none;
color: #888;
}
@media only screen and (min-width: 768px) {
#cookie-notice {
bottom: 1rem;
border-radius: 0.25rem;
}
.cookie-notice-close {
float: right;
}
}
</style>
Notice block: Add the following code to your HTML <body></body>
section.
<div id="cookie-notice">
We use cookies to deliver better experience.
<a href="https://about-cookies.eu.org" class="cookie-notice-more" target="_blank" rel="noopener">More info...</a>
<a href="javascript:void(0)" class="cookie-notice-close" onclick="closeCookieNotice()">OK</a>
</div>
Script: Add the following code to your HTML footer before the </body>
closing tag.
<script>
function closeCookieNotice() {
const nowDate = new Date();
const expireDate = new Date(nowDate.setDate(nowDate.getDate() + 30)).toUTCString();
document.cookie = "cookie_notice=0;path=/;expires=" + expireDate + ";SameSite=Lax;";
document.getElementById("cookie-notice").style.display = "none";
};
document.addEventListener("DOMContentLoaded", function() {
const cookie_notice = ('; ' + document.cookie).split('; cookie_notice=').pop().split(';')[0];
if (cookie_notice !== "0") {
document.getElementById("cookie-notice").style.display = "block";
}
});
</script>
External installation
CSS: Add the following code to your HTML <head></head>
section.
<link rel="stylesheet" href="dist/css/cookienotice.min.css">
OR
<link rel="stylesheet" href="https://cookienotice.js.org/cookienotice.min.css">
HTML: Add the following code to your HTML <body></body>
section.
<div id="cookie-notice">
We use cookies to deliver better experience.
<a href="https://about-cookies.eu.org" class="cookie-notice-more" target="_blank" rel="noopener">More info...</a>
<a href="javascript:void(0)" class="cookie-notice-close" onclick="closeCookieNotice()">OK</a>
</div>
JS: Add the following code to your HTML footer before the </body>
closing tag.
<script src="dist/js/cookienotice.min.js"></script>
OR
<script src="https://cookienotice.js.org/cookienotice.min.js"></script>
Bundle installation
Note: Use this type of installation if you like the English version text and look of the standard cookie notice theme (view it). This requires to include only one JS file.
Add JavaScript: Add the following code to your HTML <head></head>
section or in your HTML footer before the </body>
closing tag.
<script src="dist/js/cookienotice.bundle.min.js"></script>
OR
<script src="https://cookienotice.js.org/cookienotice.bundle.min.js"></script>
Explore Themes
You can customize your cookie notice look thanks to themes.
Frequently Asked Questions
header.php
and/or footer.php
and insert the Cookie Notice code. By default those files are located in the /wp-content/themes/your-current-theme/
directory.