UPDATE: Having problems? Fragment caching stopped working? See the updated article with information on using W3 Total Cache fragment caching with the new W3TC_DYNAMIC_SECURITY constant which was implemented for security reasons.

W3 Total Cache is a great plugin for speeding up your WordPress website with page cache, database cache, minifying JS and CSS, object cache, content delivery network and more.

A problem could arise with dynamic code and a certain part of code might be cached with W3 Total Cache which you don’t want to cache. You can use the MFUNC fragment caching in your code to prevent this.

Here is an example of using W3TC MFUNC comments:

<!-- mfunc CODE1 -->CODE2<!-- /mfunc -->

CODE 1 above is the code to execute with W3TC enabled and the page currently cached.
CODE 2 above is the code to execute with W3TC disabled or the page not cached.

Of course, in the above example CODE1 and CODE2 will most likely be the same code.

Say you have code like this for example:

echo "This is my website";

You can implement it like this

<!-- mfunc echo "This is my website cached"; --><?php echo "This is my website not cached"; ?><!-- /mfunc -->

Good luck with it!