WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
Fragment Caching on function file (6 posts)

  1. Xcellence IT
    Member
    Posted 1 year ago #

    I have a one form, and I'm inserting it on page footer from a function file. I need to display a random form to each visitors and thus have a function developed to support this. However, with caching enabled the randomness doesn't work.

    The site is http://www.nopaccelerate.com/

    So here, I need to exclude certain section of code from caching.

    I tried to put the function inside Fragment Caching which should do the trick, but it gives parse error on the line where I added following code:

    <!--MFUNC {the W3TC_DYNAMIC_SECURITY string}           -->
       //echo rand();
       // I have my custom code here
    
    <!--/mfunc {the W3TC_DYNAMIC_SECURITY string} -->

    Any idea, how to use fragment caching on function file? I am fine with any other idea that works.

    Looking forward to your response.

    Thanks

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    What's the exact parse error?

  3. Xcellence IT
    Member
    Posted 1 year ago #

    Hi Frederick, we got it fixed, it was nothing more than a syntax error. However, I'm still not able to exclude particular block in function file that runs on all our page by inserting it into footer.

    We need to pass a random integer from a given array and based on that it loads random form in the footer.

    Here is a code snippet for you to review:

    <!--MFUNC {E7C5F12EBCDA5F83A41BF33D778ED} -->
       <?php
            //echo rand();
            $surveyforms=array("10","11");
            $ra=$surveyforms[array_rand($surveyforms)];
            echo($ra);
        ?>
    <!--/mfunc {E7C5F12EBCDA5F83A41BF33D778ED} -->

    This should print a random number from an array collection given every time a page is refreshed, however due to cache the result. If we disable caching then it works fine, however as you know caching is very important for performance so we can not disable it.

  4. Xcellence IT
    Member
    Posted 1 year ago #

    I have also tried putting this into footer file directly... but found that this doesn't work there as well.

    May be a bug?

  5. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    Remove the {},theyre just an unclear placeholder.

  6. Xcellence IT
    Member
    Posted 1 year ago #

    Hi, thanks for your response.

    This doesn't work either. Pls advise.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic