Show Me The Cookies: How to list all cookies on your WordPress site

I’ve been working on a new plugin for WordPress called Cookies. It shows you a list of all cookies on your current site. Once activated, you can find this list under Appearance – Cookies.

In addition, you can also display this list to your visitors by adding the shortcode [cookies] to any post or page. Many of those cookies are used by WordPress to track things such as “are you logged in”, so I’ve added an option to filter WordPress related cookies out. This list is available with the [cookies-nowp] shortcode.

I’m still putting the finishing touches on the plugin, but I’m planning to submit it to the WordPress repository. For now, feel free to download it from my GitHub repository.

Let me tell you a bit about how this plugin came to be.

History

A few months ago, John contacted me via Facebook. He had been using one of my other code snippets for many years, and wondered if I could help him add a modification to it. We messaged back and forth and came up with a modification to an existing plugin that needed a small tweak to make it work for his project. John was so pleased with the outcome that he decided to become one of my Patreon Supporters. How nice is that?

A little while later, John contacted me again and showed me a piece of code originally written by David Artiss in 2012. It lists all cookies on a WordPress site, using a shortcode so that the list can be shown to visitors. David was baffled to find that at the time, no plugin in the WordPress repo could do this, so he decided to write his own snippet and made it available on GitHub:

As of March 2019, I still haven’t found such a solution on WordPress – unless it has such an obscure title that it’s deeply hidden in the vast collection of current plugins.

The original code needs to be pasted into the current theme’s functions.php file. John wondered if I could write a filter so that all WordPress related cookies could be eliminated from the list. After a bit of tinkering I came across a filter function on StackExchange, courtesy of ejunker. It’s deceptively simple yet very powerful:

When I put everything together, I thought this would make a great standalone plugin. Perhaps not everybody wants to show the list of cookies to their visitors, so I thought I’ll add this as an “admin-only” option as well. Now we have two options, a public one and a private one – filtered and unfiltered.

Contributions welcome!

I wanted to get the plugin out quickly in the limited amount of time I’ve had yesterday, and it works well – however it’s not coded as elegant as I’d like it to be.

For example, I’ve chosen to duplicate functionality rather than extend it, I didn’t build an options dialogue in the admin interface and chosen a second shortcode. I wanted to keep it quick and simple, much like David did in his original code. I may add other functionality over time – send me a pull request if you have any ideas.

I’ll have a look for an available name on WordPress and will submit it to their repo as well. My guess is that “Cookies” might already be taken, but perhaps “Show me the Cookies” will work well.

Download and Install

  • head over to https://github.com/versluis/Cookies
  • download the latest version (as a ZIP)
  • in WordPress, upload it under Plugins – Add New – Upload Plugin
  • activate it
  • in WordPress, head over to Appearance – Cookies and enjoy

Any questions, please let me know!

Jay is founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or drawing on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

You can leave a comment on my original post.