Fragment Cache with Shortcode results in same cached output
-
We’ve been trying for two days now to get W3 Page Caching working with fragment caching properly. Our site uses the latest wordpress, elementor, woocommerce, etc. and we found right after going live an issue where Booster’s multicurrency plugin’s content gets cached like all other page content. So someone from region-A goes to the site and the currency is auto-set-by-region, that builds the page cache. Then when someone from region-B goes to the site, all currency info and pricing are already ‘pre-set’ from the cache created by the region-A user. Not good.
Now – we eventually got code like below to work (< and > replaced with = so the code will display here):
=!–mfunc FRAGMENT_CACHING –=
echo date(“H:i:s”);
=!–/mfunc FRAGMENT_CACHING –=But we’ve tried every method and combination trying to get a shortcode to work, like:
=!–mfunc FRAGMENT_CACHING –=
echo do_shortcode(‘[all_tracking]’);
=!–/mfunc FRAGMENT_CACHING –=All this shortcode currently does is output the user’s IP address via 2 different means – very simple. The problem is that in the cached file, examples like the first one above are preserved because they haven’t run yet, but the 2nd example with the shortcode has the shortcode already run and so it’s saved in the cache file like:
=!–mfunc FRAGMENT_CACHING –=
echo do_shortcode(‘REMOTE_ADDR: 47.128.xx.xx
HTTP_X_FORWARDED_FOR: 47.128.xx.xx
‘);
=!–/mfunc FRAGMENT_CACHING –=When the page is then requested, there is of course no shortcode with such a name so the page simply outputs the contents between the (‘ and ‘) – resulting in essentially the same result if we hadn’t done the mfunc stuff to begin with.
So how do we get the shortcode to be preserved as the actual pre-processed code?:
echo do_shortcode(‘[all_tracking]’);Thanks!
The page I need help with: [log in to see the link]
- The topic ‘Fragment Cache with Shortcode results in same cached output’ is closed to new replies.