Enrich Your WordPress Knowledge Regularly
How to Show Cookie Notice on WordPress Site Without any Plugins
What is Cookie?
A “cookie” is a piece of information that is stored on your computer’s storage and which records how you move your way around a website so that, when you revisit that website, it can present tailored options based on the information stored about your last visit. Cookies can also be used to analyze traffic and advertising and marketing purposes.
Cookies are used by nearly all websites and do not harm your system.
What is Cookie Law?
According to cookielaw.org
The Cookie Law is a piece of privacy legislation that requires websites to get consent from visitors to store or retrieve any information on a computer, smartphone, or tablet.
It was designed to protect online privacy by making consumers aware of how information about them is collected and used online and giving them a choice to allow it or not.
How to use a Cookie consent message on my site?
This tutorial will show you how to set up a cookie notice on your WordPress website without installing plugins. Then, I will add a piece of code to use that.
Generally, in WordPress, you can do this simple task by using any cookie consent plugins, but as you may be concerned, installing every additional plugin in your WordPress site will increase the loading time of your website. Before starting, you may need
Step 1 — Generate the Cookie Notice Code
Visit cookieconsent.insites.com site.
Over there, you can select your message displaying position (anyone). The default position for this message is Banner bottom.
You can also change your message box layout.
You can also choose a different theme/palette for your message layout, or you can create a new one.
You can anchor your custom cookie privacy page in the Learn More Link section or leave it as default.
In this Compliance section, you can set the cookie compliance type. If you are not aware of this, then leave it as default.
You can set your own Custom Cookie Text Message in the Custom Text section. If you are not aware of this, then leave it as default.
If all’s okay, copy the right-side generated code from there.
Well done, now we have to insert this piece of code into our site.
<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>
Step 2 — Insert the Code in WordPress Site
Log in to your WordPress Admin panel and navigate to Appearance
Editor:
Now, open the header.php file and paste the above-generated code in the header.php file, just before the tag. Then click on Update File to save.
That’s all. You have successfully inserted a cookie consent message into your website.
Note: Before editing the header.php file, I recommend you keep a backup file so that if it’s going wrong, you can restore the file.