Skip to content

Instantly share code, notes, and snippets.

@avioli
Created June 25, 2015 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avioli/0cfd7987a66f418ab563 to your computer and use it in GitHub Desktop.
Save avioli/0cfd7987a66f418ab563 to your computer and use it in GitHub Desktop.

W3 Total Cache and dynamic code

How do I implement fragment caching?

Edit your templates to with the following syntax to ensure that dynamic features remain so:

  • Example 1: <!-- mfunc any PHP code --><!-- /mfunc -->
  • Example 2: <!-- mfunc -->any PHP code<!-- /mfunc -->
  • Example 3: <!--MFUNC -->echo rand();<!--/mfunc -->
  • Example 4: <!-- mclude path/to/file.php --><!-- /mclude -->
  • Example 5: <!-- mclude -->path/to/file.php<!-- /mclude -->

How can I prevent caching directly in my templates etc?

It's possible to empty the entire cache or simply purge the cache of a single post / page:

  • Purge the entire page cache: if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); }
  • Purge a single post / page by passing it's ID: if (function_exists('w3tc_pgcache_flush_post')) { w3tc_pgcache_flush_post($post_id); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment