1

The code shows closed/open label depend on time. It shows correct html only if i refresh page, but if i close page and open again nothing will change. How to prevent this code from being cached(only this code)? if its not possible then how to disable cache for particular page where the code is? I use WordPress.

<span class="shop-status <?php $status; ?>"><?php echo($status); ?></span>
Tod
  • 187
  • 3
  • 13
  • This kind of caching is usually done in the browser, not the server. The way to control, somewhat, what a browser caches is by using headers (http://php.net/manual/en/function.header.php) or, if you have to, meta tags (https://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers?answertab=active#tab-top) – KIKO Software Mar 09 '18 at 22:40
  • https://stackoverflow.com/questions/24763906/prevent-caching-of-dynamic-php-content – Mohammed Elhag Mar 10 '18 at 10:01
  • thanks you for replies, but i want to know if there is way to disable cache for piece of code or for one page, not for all website? – Tod Mar 10 '18 at 11:31
  • If you use any caching plugins (e.g. W3 Total Cache), then it's likely that there is an option for you to disable caching on certain pages. Try looking through the plugin's documentation or support forums. – Sally CJ Mar 11 '18 at 00:45
  • I am using the one you mentioned, and i tried with their function called "fragment caching" but it doesnt work, browser still cache my html code and change it only after refreshing page. – Tod Mar 12 '18 at 14:28
  • So I suppose you're using W3TC Pro version? Take a look at https://www.justinsilver.com/technology/wordpress/w3-total-cache-fragment-caching-wordpress/ and follow the steps outlined there. If you still couldn't get it to working properly, then perhaps you should share the template code. And did you actually flush the W3TC cache *after* you applied the fragment caching technique? If not, then do so and see if that helps. [Another link that might help.](https://www.wpblog.com/improve-wordpress-performance-by-configuring-w3tc/) – Sally CJ Mar 15 '18 at 00:49

0 Answers0