That was 1998!
The Reeling in the Years for 2016 will be an eye-opener, but I bet 2019 will be even crazier.
That was 1998!
The Reeling in the Years for 2016 will be an eye-opener, but I bet 2019 will be even crazier.
EDIT: Updated for WP Super Cache 1.6.3 and newer.
More sites use cookie banners now that the GDPR is active but some are finding that their banners are misbehaving once they enable caching.
This is a similar issue to the one that happened to some page counter plugins in the past. The page counter wouldn’t increment.
When a cookie banner is clicked a cookie is set in the browser so the website knows this visitor has agreed to accept cookies. If the cookie is set then the cookie banner html is not sent to the browser.
I suspect the main issue is that the code that sets and checks if the cookie is set is PHP. Unfortunately because the page is cached then no PHP code is executed, and the cookie banner is displayed because it was originally cached that way.
Since WP Super Cache only knows about certain WordPress cookies it assumes everyone who doesn’t have those cookies is a first time “anonymous” visitor. It doesn’t know about your cookie banner cookie.
You have two options:
Using Javascript completely is a better solution because it runs in the browser on every page load but that might not be possible every time.
Otherwise, use PHP to get WP Super Cache to play nicely with your existing code. You basically need to run do_action( 'wpsc_add_cookie', 'cookie_name' );
after init
so WP Super Cache adds the cookie name to its cookie list. This only needs to be done once, but you can leave it run all the time because it will only ever add the cookie name once. This also ensures the name is added again if the WP Super Cache configuration file is ever reset or deleted.
wpsc_add_cookie
action in a function that loads on “init”./*
* Tell WP Super Cache to cache requests with the cookie "eucookie" separately
* from other visitors.
*/
function add_wpsc_cookie_banner() {
do_action( 'wpsc_add_cookie', 'eucookie' );
}
add_action( 'init', 'add_wpsc_cookie_banner' );
Substitute the name of the cookie (eucookie) for your cookie name.
When your plugin is uninstalled it should remove your cookie with the following:
do_action( 'wpsc_delete_cookie', 'eucookie' );
For future reference, since cookie banners will hopefully not be around forever, here’s what they looked like in the deep, distant past of 2018. 🙂
The latest episode of Hardcore History is another amazing audio tour through history, even if Dan Carlin himself says he is unqualified and it might not be completely accurate. He’s a great story teller. This one covers the rise of Japan in the early twentieth century and beyond.
Dan’s coverage of the Manchurian Incident reminded me I have to re-read the Tintin story, “The Blue Lotus“. HergĂ© definitely applied his imagination when recounting how the train track was blown up but I’d never have known about that period of time if I had never read that book.
And similarly, I wouldn’t have known the railway track was barely damaged if I hadn’t listened to Hardcore History!