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.

At the moment I run PHP code in my side bars. Even though I have the following

header("Pragma: no-cache");
header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

It still appears to serve cached content.

share|improve this question

closed as off-topic by Mark Kaplun, G. M., ialocin, birgire, Pieter Goosen Aug 23 at 9:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Mark Kaplun, G. M., ialocin, birgire, Pieter Goosen
If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers 3

up vote 3 down vote accepted

This can be accomplished with fragment caching feature that W3TC has. Had been asked/answered couple times.

share|improve this answer

You'll probably need to find a solution that loads this content via JavaScript...unfortunately. That's the only way around this issue that I've found. I've solved it by building a container and a separate (non-cached) PHP file that gets whatever content you'd want in the sidebar.

Then...use jQuery's ".load" to pull the PHP content into that container on the cached page. Works well for me here: http://www.missouladowntown.com.

Hope that helps.

share|improve this answer

Those headers which you've put in your question apply to the entire page, you can't set them just for a sidebar as the page has already been loaded at this point.

You could do as Ross said and alternatively load the sidebar fragment after the page has loaded via ajax, or you could use an iframe to load in. You could then use the headers to set the expiry of the sidebar content separately to the main page.

share|improve this answer

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