• I have a PHP query in my website which detects if the user is on a desktop and displays a part of the header (and therefore leaves out the header on mobile, which is what it’s intended to do).

    It was working perfectly but now I’ve started using Page Caching, when I visit the site on mobile, the part of the header is now showing, due to the cache.

    Is there a way I can exclude this PHP query from being cached at all please? It’s in my header.php.

    The website is https://www.bitofageek.com if you need to look. Thanks.

    https://www.ads-software.com/extend/plugins/w3-total-cache/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ransom1337

    (@ransom1337)

    The code I need to stop caching is this, if it helps anyone aid me:

    <?php if (wpmd_is_notphone()) { ?>
    <div class="sidebar_wrapper">...</div>
    <? }; ?>

    Have you found a solution to your problem ? I’m interested as well!

    How do I implement page fragment caching?

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

    define(‘W3TC_DYNAMIC_SECURITY’, ‘somesecurestring’);

    Edit your templates with the following syntax to ensure that dynamic features remain so. Replace with content of the constant:

    Example 1:
    <!– mfunc {the W3TC_DYNAMIC_SECURITY string} any PHP code –><!– /mfunc {the W3TC_DYNAMIC_SECURITY string} –>
    Example 2:
    <!– mfunc {the W3TC_DYNAMIC_SECURITY string} –>any PHP code<!– /mfunc {the W3TC_DYNAMIC_SECURITY string} –>
    Example 3:
    <!–MFUNC {the W3TC_DYNAMIC_SECURITY string} –>
    echo rand();
    <!–/mfunc {the W3TC_DYNAMIC_SECURITY string} –>
    Example 4:
    <!– mclude {the W3TC_DYNAMIC_SECURITY string} path/to/file.php –><!– /mclude {the W3TC_DYNAMIC_SECURITY string} –>
    Example 5:
    <!– mclude {the W3TC_DYNAMIC_SECURITY string} –>path/to/file.php<!– /mclude {the W3TC_DYNAMIC_SECURITY string} –>

    Be aware that WordPress functions will not be available.

    Plugin Contributor Frederick Townes

    (@fredericktownes)

    Thanks @manoucho, @ransom1337 does that answer your questions?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is there a way to make specific lines of code not cache?’ is closed to new replies.