Enabling Jetpack’s Cookie Notice On A Theme Without Widget Areas

Jetpack is considered by many to be the Swiss Army Knife of WordPress plugins. It can add tons of functionality to your site with just a few clicks. There unfortunately is a bit of opposition to it in the community but I don’t buy into the hate. However, like most software, I also don’t believe some of the approaches are ideal.

One of the more useful features since the introduction of the GDPR is the Cookies & Consent Banner. I tried to activate it the other day and to my dismay it’s only implemented via a widget. I think this is quite silly, seeing as it displays fixed to the browser window rather than in a widget area. It would be sufficient for most sites and I do understand the practicality of it, but my site is a custom theme with no widget areas. As a result, I couldn’t activate the notice.

Thankfully, I figured out a workaround. Widget classes have a certain standard that they need to follow in order to work properly, and we can take advantage of this by instantiating the Jetpack_EU_Cookie_Law_Widget class without needing to deal with widgets. Simply copy and paste the code below into your theme’s functions.php file and make sure the “Extra Sidebar Widgets” module in Jetpack is active.

The default settings should be enough for most sites, but if you need to change the settings simply update the $instance array, the available options can be found on Github.

Did you find this post useful?