Learning never exhausts the mind
Home >  Web Design > WordPress > EU Cookie Law WordPress Plugin

Published 13th June 2012 by

The Cookie Law is a new piece of privacy legislation from Europe that requires websites to obtain consent from visitors to store or retrieve cookies and is designed to protect online privacy, by making consumers aware of how information about them is collected by websites, and enable them to choose whether or not they want to allow it to take place. This tutorial and download shows you how to implement an 'implied consent' notification message.

Update 17/06/2013: Major update to the WordPress Cookie plugin. Changes include fully responsive layout, new configuration manager, improved control over styling and more configuration options. See notes below for details.

The Cookie Law

The Cookie Law was started as an EU Directive that was adopted by all EU countries on May 26th, 2011. At the same time, the UK updated its Privacy and Electronic Communications Regulations, which brought the EU Directive it into UK law. Each EU member state has done or is doing the same thing. Although they all have their own approach and interpretation, the basic requirements of the directive remain the same.

Many people are unaware that the law is already in effect in the UK. However, the UK's regulator, The Information Commissioner's Office (ICO), gave everybody a one year 'grace period' for implementing a solution which expired on 26th May 2012.

In a nutshell, the requirements of the directive mean that website operators must get "informed consent" from users before they record any detailed information in the cookies they store on visitors' computers. This means that a website must ask for consent from the user before using cookies.

Are all cookies affected? The vast majority are - all cookies that are not "strictly necessary for a service requested by a user".

Tracking cookies used by Google Analytics are affected as well, so even if your website does not use cookies, but you use Google Analytics (or possibly any other similar products) still need consent from the user.

There are two methods for gaining consent - explicit and implied.

  • Explicit consent means that a website will not use any cookies unless the user explicitly agrees to "opt-in" to receiving cookies.
  • Implicit consent means that a website will continue to use cookies and that it is up to the user to "opt-out" by changing their browser cookie preferences or by leaving the site.

A Solution

This method relies on implied consent and you should ensure that this method is correct for your website. If you are relying on implied consent you need to be satisfied that your users understand that their actions will result in cookies being set. Without this understanding you do not have their informed consent (further info here)

This code and WordPress plugin will create a small banner at the top of the guest's browser that greets them with the message:

Wordpress Plugin: EU Cookie Law

Wordpress Plugin: EU Cookie Law

You can change this text from within the plug-in settings page.


Whilst every effort has been taken to ensure that this code remains up to date and conforms to the EU Cookie Law, the authors cannot and will not be held responsible if it is found to be inadequate in any way. The authors are NOT legal experts and nothing contained within constitutes legal advice.

It is your responsibility to ensure that implied consent is suitable for your site before using this code or plugin.

For more information on the Cookie Law please visit the The Information Commissioner's Office.

See it in action:

View on CodePen

On the first visit to the website, the user will see a banner across the top of the page as shown in the screenshot above. If they continue to use the site the message is not shown, nor will it be shown again. The plugin and code set a cookie to determine if the message has already been shown. This cookie is deemed essential to the services provided and is excluded from the regulation. The cookie is called visited and the value is set to yes. The cookie has a far-future expires date.

The code is very straightforward, it first checks to see if cookies are enabled or not on the guest's browser. If they are then it checks to see if the message has already been shown using the presence of the visited cookie. If the cookie does not exist then the message is added to the top of the page, it has an expanding type animation when shown. The close button will shrink the message in the same way as it is shown and finally the cookie is set so that the message isn't shown again.

WordPress Plugin

The WordPress plugin can be downloaded from the WordPress Plugin Directory or using the link below: EU Cookie Law Complience Message.

EU Cookie Law WordPress Plugin (6.72 kB)


If you are using the WordPress plugin:

  1. Upload all files to the '/content/plugins/' directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Configure the text through the 'Settings' menu under 'EU Cookie Message'

Configuration Options

Using the WordPress plugin you are able to customise the title, message and the close button text as well as changing the visual style using a built-in light or dark theme, or creating your own.

Content Padding: This option allows you to change the padding inside the main content section to increase the space around the borders.

Message Maximum Width: Change this to suit your website maximum page width. This is the maximum width that the text will occupy.

Message hovers over content: By enabling this option you can have the cookie warning message placed above your website header - it will push the header below the message. The default is for the message to "hover" on top of the website header.

Debug Mode: This prevents the plugin from setting a cookie. You can use this for testing and the message will be shown on every page load. Remember to disable debugging when your site goes into production.

Pure HTML & Javascript

If you are going to be using the above code on a non-Wordpress website you may need to edit the template or theme. Methods will vary on how your website is written, but in general, all you need to do is include the jQuery library to every page that will contain the message and paste in the above snippet into the page just before the end of the body tag.

There are two lines in the javascript, one contains the HTML for the message, the other contains the stylesheet. You can edit these to change the look and feel of the message.

Using an xHTML Transistional Skeleton template it should be structured similar to this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <title>Your Title</title>
  <meta name="Description" content="Your description" />
  <meta name="Keywords" content="Your, comma delimited, keywords" />
  <meta equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" type="text/css" media="all" href="your-css-stylesheet.css" />
</head >
  <!-- YOUR CONTENT HERE -->  
  <script type="text/javascript">
      if (navigator.cookieEnabled === true)
        if (document.cookie.indexOf("visited") == -1)
          // The message
          jQuery('body').prepend('<div id="cookie"><div id="wrapper"><h2>Cookies on this website</h2><p>We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies from this website. If you would like to change your preferences you may do so by following the instructions <a href="http://www.aboutcookies.org/Default.aspx?page=1" rel="nofollow">here</a>.</p><div id="close"><a href="#" id="closecookie">? Close</a></div><div style="clear:both"></div></div></div>');
          // The CSS
          jQuery('head').append('<style type="text/css">#cookie {position:absolute;left:0;top:0;width:100%;height:100%;background:rgb(0,0,0);background:rgba(0,0,0,0.8);z-index:9999;}#cookie #wrapper {padding:20px;}#cookie h2 {color:#ffffff;padding-top:0;display:block;text-align:center;font-family:ariel,sans-serif;font-size:1.8em}#cookie p {color:#BEBEBE;display:block;font-family:ariel,sans-serif;font-size:1.4em}#cookie #close{text-align:center;}#closecookie{color:#ffffff;font-family:ariel,sans-serif;font-size:1.6em;text-decoration:none}@media only screen and (min-width: 480px) {#cookie {height:auto;}#cookie #wrapper{max-width:980px;margin-left:auto;margin-right:auto;}#cookie h2{width:18%;margin-top:0;margin-right:2%;float:left;text-align:right;}#cookie p {width:68%;margin:0 1%;float:left;}#cookie #close{width:9%;float:right;}}</style>');
          // Don't touch this
          jQuery('#closecookie').click(function() {jQuery('#cookie').hide("fast");});
          document.cookie="visited=yes; expires=Thu, 31 Dec 2020 23:59:59 UTC; path=/";  
20 thoughts on “EU Cookie Law WordPress Plugin
  • 26th March 2016 at 12:00 am

    I use your plugin for EU Coookie message on my site http://rizbit.uk

    my them shows a menu at top of screen that stays fixed on screen when you scroll. The problem I noticed is that the menu bar is placed on top of and thus blocks the EU cookie message.

  • Simon Kindlen
    8th July 2015 at 12:00 am


    Hope your are doing well. Your European plugin has been a dream to set-up and use.

    I have been using your plugin for EU Cookie Law Compliance Message on my website and other website without any issues. Until today when I updated the plugins on the website. Getting the following error:

    Fatal error: Cannot redeclare hex2rgb() (previously declared in /home/kindlene/public_html/wp-content/plugins/eu-cookie-law-consent/index.php:333) in /home/kindlene/public_html/wp-content/plugins/js_composer/include/helpers/helpers.php on line 1169

    To get the website on-line I renamed the plugin folder for European plugin. Then deactivated the plugin for WPBakery Visual Composer which was clashing with your plugin. Having the notice is more important.

    Are you aware of this issue? Will there be update to fix the issue?



    • 10th July 2015 at 12:00 am

      Thanks for reporting your issue with the plugin. I shall look into this and issue an update in the next day or so.

  • 2nd March 2014 at 12:00 am

    thanks for your great plugin.

    I would like to know, if the incompatibility to certain characters is still observed?

    The plugin seems to work in admin mode but not when logged out.



  • 18th February 2014 at 12:00 am


    Thanks for handy plugin. Is it possible to put message on the bottom or side of the page?


    • 19th February 2014 at 12:00 am

      Yes you can, all you need to is change the CSS. Try adding #cookie {position:bottom} to the custom stylesheet to have it positioned at the bottom, or #cookie {top:0;left:0;width:200px;height:100%} to have it positioned on the right and 200px wide. I haven't tested this, but it should work.

  • Rodolfo Buaiz
    31st August 2013 at 12:00 am

    Hi Tim, I installed the plugin in my dev environment and it is displaying some PHP notices when WP_DEBUG is enabled. I normally like to correct this things, went ahead, and ended rewriting the whole plugin.

    You can take a look at https://github.com/brasofilo/European-Law-Compliance-Message. The readme file has a summary of the changes. I modified the cookie checking scheme, but am not really sure. If you like the result, we can continue the conversation at GitHub.

    Cheers and thanks for sharing  :) 

  • Bangladesh
    28th July 2013 at 12:00 am

    Used this awesome plugin for cookie on my website works just super. Thanks guys.

  • 19th June 2013 at 12:00 am


    First of all thanks for this great plug-in. There is one problem, when I activate the plug-in my WordPress admin bar at the top of my website dissapears. Do you know what i could do about that?


    • 19th June 2013 at 12:00 am

      Hi Martijn

      There was a bug that removed the admin bar, it was a test line that I added during development and forgot to remove. Version 2.01 has been committed to WordPress repository and fixes this. Please update from WordPress.Org and the admin bar will be shown again.


  • 26th April 2013 at 12:00 am


    I need your help with eu-cookie-law. I want to put this banner on my site, but not on the top of the page because it covers buttons on the page. Can you explain me how to (which value to change) or make for me some code to put banner position little down, or on the bottom of the page. I know taht is very easy for coders but not for me.

    Thank you!

  • Ula
    12th April 2013 at 12:00 am


    I installed your plugin for a wordpress site and it worked, but after changing the default infos it's no longer visible. Can you help me? Do you have you clue what could be wrong?

    The adress is http://www.open5.pl

    Thank you!


    • 19th April 2013 at 12:00 am

      Hmm.. I suspect that there is an incompatibility a certain character in Polish which has triggered a Javascript error which has caused the cookie message not to show.

      I can see the code in the source of your site, and it looks like the error occurs after "aktualnymi", Javascript does not seem to like the character after it. Did you insert a newline or carriage return? Judging by the sentence construction I'd guess not. I'll take a look and get back to you.

      As a side note, I will be releasing a new version shortly which fixes a problem with incorrectly escaped characters and mobile integration which may help. Watch this space.


  • 7th January 2013 at 12:00 am

    I prefer the idea of implied consent, basically anything to put fewer barriers in front of my visitors is a good thing. One thing this plugin doesn't appear to feature is the recognition of where a visitor comes from. In other words, if someone visits from say Australia there's no need for him to see any cookies message. Any plans to incorporate that feature in your plugin at all?

  • 20th September 2012 at 12:00 am

    Thanks for releasing this.

    I'd like to use it, but my site's html. Could you please update it so it works in all browsers?

    I appreciate this resource very much, think it looks great.

    • 29th November 2012 at 12:00 am

      Hi Mary,

      Updated code sample should work in browsers, but not on locally as cookies are disabled on local pages. You can easily comment out the cookie check though.


  • 25th August 2012 at 12:00 am


    I have added some of my own text to the default provided. However, this means the text no longer fits inside the black semi-transparent background. Which parameter needs to be larger in order for this to work?

    Thank you for this excellent plugin.

    Kind regards

  • 12th August 2012 at 12:00 am

    Hi, thanks for this lovely plug-in.
    I didnt really like the rather subtle nature of the plug-in so was playing with the CSS and made it rather bigger. Somehow during this - kept deleting the visited cookie and reloading page it suddenly stopped working!!!
    I have removed and re-installed the plug-in but to no avail. It still does not work.
    What did I do and how can I correct it?


    • 29th November 2012 at 12:00 am

      Do you get any error messages at all? Have you inadvertently disabled cookies on the page? Try commenting out the cookie enabled and cookie value checks and see if that makes any difference.

  • 25th June 2012 at 12:00 am

    Unreadable on IE8.
    Since c. 18 - 34 % of users on different sites I'm responsible for use IE8 this would be unacceptable to me.

    But I've made a quick fix by replacing the transparent background with a solid colour. Would be preferable if CSS was separate so could be styled as desired.

    I appreciate the non-WP instructions as I have a site that is a mixture of both.


Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.