A PHP MODX Revolution extra to automatically comply with EU cookie law

Last modified: 31/05/2018 - 2 years, 5 months ago

Requirements: MODX Revolution 2.2+ | PHP5+ | jQuery

Optional requirements: Bootstrap

Download: MODX Installer | MODX Repository | GitHub

A project tagged as: modx, php, plugin

Twitter Facebook Reddit


For sites that have visitors in the European Union (EU), the EU cookie law states that each visitor must give their consent for most cookies to be used. The usefulness or benefit of this is a devisive subject!

CookieConsent displays a message informing each visitor that the site uses cookies, with a link to your site's cookie policy.


Property Description Default
cookieDays The number of days the cookie should last for 365
cookieName The name of the cookie that determines whether consent has been given CookieConsent
idCookiePolicy ID of resource containing site cookie policy
tpl The name of the chunk containing the cookie disclaimer cookieConsent
class The name of the class selector for the CookieConsent HTML cookieconsent
includeCSS Whether to include the CSS file
includeJS Whether to include the JavaScript file
pathCSS The location of the CSS file. Use the {assets_path} placeholder as a shortcut. Must include ".css" {assets_path}/.../cookieconsent-min.css
pathJS The location of the JavaScript file. Use the {assets_path} placeholder as a shortcut. Must include ".js" {assets_path}/.../mabCookieSet-min.js

The CookieConsent plugin is run on the OnWebPagePrerender system event.

Custom properties

Setting your own custom properties for a MODX plugin takes a bit more effort than that required for a snippet.

To set your own properties, do the following:-

  • Open the CookieConsent plugin and go to the Properties tab
  • Add a new Property Set
  • Set your custom values
  • Now go to the System Events tab
  • Update the Property Set field for the OnWebPagePrerender with the name of your custom Propert Set

You will need to update the OnWebPagePrerender event with the name of your custom Property Set any time you upgrade your CookieConsent plugin. This is the way MODX handles the upgrade of a package plugin. However, the values you set in your custom Property Set will be saved between upgrades.


By default, CookieConsent appends a disclaimer to the body tag if consent has not been set. The disclaimer is positioned using CSS.


CookieConsent uses a simple chunk which contains the cookie disclaimer message and the call to the jQuery plugin that will save their response to a cookie.


The chunk displayed to the user. Can be set using the tpl property. It uses a Bootstrap theme.

<div data-name="[[+cookieName]]" data-value="[[+cookieValue]]" data-days="[[+cookieDays]]"  class="alert alert-warning alert-dismissible fade in [[+class]]" role="alert">
  <p class="text-center">
    We have placed cookies on your device to help make this website better. You can view our <a title="View out cookie policy" href="[[+idCookiePolicy:gt=`0`:then=`[[~[[+idCookiePolicy]]]]`:else=`/`]]">cookie policy here</a>.     
    <button type="button" class="btn btn-info" data-dismiss="alert">Continue using site</button>

    $(".[[+class]] button").click(function ()
      $(".[[+class]]").mabCookieSet({onDone: function(){$(".[[+class]]").hide();}});

Custom chunk

To customise CookieConsent, simply make your own chunk based on the one above, and name it CookieConsent.

jQuery plugin

CookieConsent includes a jQuery plugin that sets a cookie so that it remembers whether the current visitor has accepted your cookie policy.


The jQuery plugin is automatically included unless includeJS is set to false. You might do this if you have your own script you'd like to use to add a cookie. If so, you could instead set pathJS which will automatically include your own script.

The mabCookieSet plugin can be triggered via JavaScript. It is triggered for you in the defualt chunk, as detailed above.

$( ".cookieconsent" ).mabCookieSet();


Options are passed via data attributes or set directly in the call as options. For data attributes, append the option name to data-, as in data-name="CookieConsent".

Name Type Default Description
name string CookieConsent The name of the cookie
value string   The value of the cookie
days number 365 The number of days the cookie will last for



CookieConsent by mad about brighton is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Permissions beyond the scope of this licence may be available by contacting me.