wordpressw3-total-cache

W3 Total Cache and fragment cache - not able get it to work


I have followed steps from there but I'm not able to get fragment cache to work (which was main reason to get PRO version)

Example code inside a template looks like:

<!--mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> --> echo 'The time is '.date( 'H:i:s', time() ); <!--/mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->

so in that case I expect to see The time is and right time but it works only once and then it shows echo 'The time is '.date( 'H:i:s', time() ); as a plain text.


Solution

  • First you need to define W3TC_DYNAMIC_SECURITY constant in your wp-config.php file

    define('W3TC_DYNAMIC_SECURITY', 'FRAGMENT_CACHING');
    

    then you can test it with the code below (any template):

    <?php echo date("H:i:s"); ?>
    <br>
    
    <!-- mfunc FRAGMENT_CACHING -->
    echo date("H:i:s");
    <!-- /mfunc FRAGMENT_CACHING -->
    <br>
    
    
    <div id="mydiv"><p>The current time is 
    <!-- mfunc FRAGMENT_CACHING echo date("H:i:s"); -->
    echo date("H:i:s"); 
    <!-- /mfunc FRAGMENT_CACHING -->
    </div>