Add Minimalistic Cookie Notice On WordPress Websites

Add this PHP code to your theme's functions.php file or in the Code Snippets plugin.

function cookie_notice(){?>

<p id="cookie-notice"><span>By visiting our website, you accept use of cookies and agree to <a href="/privacy-policy/" target="_blank" style="color:#001947!important;">privacy policy</a>.</span><button onclick="acceptCookie();" class="md-cookie-button">Accept</button></p>

	#cookie-notice{display:flex;align-items:center;left:50%;transform:translateX(-50%);font-family:inherit;font-size:15px;background:#ffffff; color:#001947; padding:10px 20px;position:fixed;bottom:10px;box-shadow:0 10px 20px rgba(0,0,0,.2);border-radius:3px;margin:0px;visibility:hidden;z-index:1000000;box-sizing:border-box}#cookie-notice button{color:#ffffff;background:#001947;border:0;padding:5px 10px;cursor:pointer;font-size:inherit;margin-left:10px;border-radius:3px}@media only screen and (max-width:800px){#cookie-notice{flex-direction:column;width:100%;bottom:0;left:0;border-radius:0;transform:none;text-align:center}#cookie-notice button{margin:10px 0px 0px 0px}}

<script>function acceptCookie(){document.cookie="cookieaccepted=1; expires=Sun, 1 Jan 2045 12:00:00 UTC; path=/",document.getElementById("cookie-notice").style.visibility="hidden"}document.cookie.indexOf("cookieaccepted")<0&&(document.getElementById("cookie-notice").style.visibility="visible");</script>

<?php }


What it does?

It displays a message to users about cookie usage and links to your privacy policy. Upon clicking the "Accept" button, it sets a cookie to record the user's consent and hides the notice.

Here is the demo:

What to change?

There is not much, but you can change the colors to match your site's aesthetics and also the date of Cookie Expiration (which is set to be on Sun, 1 Jan 2045). Be sure to use the correct date format as coded in <script> tag.

Is this GDPR Compliant?

No. This is useful only to tell your readers that they approve of your cookie-policy or privacy policy when they are using your website. There is no option to opt-out in here.

Depending on your audience's location, you might need to provide more detailed choices about the types of cookies users consent to (e.g., necessary, preferences, statistics, marketing).

If you are looking for GDPR compliance, you should either use a fully featured Cookie Compliant WordPress plugin or hire a WordPress developer like me.