Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use w3 total cache on a site I run which also now has to display a small popup at the bottom of the page to mention that the site uses cookies (thanks EU). The idea is that this only appears the first time the user sees the page, a cookie is then set to make sure the site doesn't show this user the popup again.

However W3 will often cache a version of the site with this popup visible meaning the popup is shown regardless of the cookie existing or not.

The popup is drawn with a <div> at the bottom of each page and it is only drawn if the cookie is set. Essentially the question is, how can I exclude W3 cache from always showing this? Is this even possible, or is there an alternative to how this popup is shown that gets around this issue?

Thanks.

share|improve this question
add comment

1 Answer

In W3TC you can specify files or cookies that are ignored and not cached.

Exclude Files from Cache
To do this go to WordPress Admin > Performance > Page Cache

In the screenshot ... you will see I've added custom sidebars from a Twenty-Eleven theme. These are excluded from being cached.

W3TC excluded files

You can also specify your custom cookie to not be cached ...

Browser Cache Settings
BUT also check your Browser Cache settings as you'll probably want to reduce these from 1 year to 1 month or week or day.

share|improve this answer
    
The problem with this is that every page potentially shows the popup and therefore uses the cookie. This would remove all pages from the cache making it pretty redundant. I'm going to have to rethink this mechanism, maybe draw the popup using javascript so that W3 won't see it when creating the cache... assuming that W3 doesn't create the cache after any DOM changes. Thanks for the help anyway –  artparks Aug 15 '12 at 13:31
    
Hi @artparks the code for your popup could be put in its own file like /includes/cookie_warning.php it would then be just this one file to exclude + the sidebar or header.php –  Damien Aug 15 '12 at 15:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.