Curious, why is your echo do_shortcode
line outside of the <?php
indicators?
I am more surprised it doesn’t display your problem 100% of the time, instead of only 10%.
Typically people have their fragment code inside the <!--mfunc <?php
area.
Are you using this partial in multiple templates or template partials? The problem might be the way that part of code is added to the website. If it works fine in a page template but not in a partial which is added through another shortcode or get_template_part()
, that might be the issue.
Thank you for the reply @gidomanders . You are right, I’m using it in the header template. So, no way to fix that?
-
This reply was modified 5 years, 8 months ago by mashastudio.
@mashastudio Sorry for the late reply.
You should never use a random string as dynamic security variable. You have to define the variable in your wp-config.php file. For security reasons, W3 Total Cache compares the string used in cached pages to the defined variable. If you randomise it, the comparison will fail and you’ll see the PHP code as normal text, like in your issue. The correct syntax is:
in your wp-config.php:
`
define(‘W3TC_DYNAMIC_SECURITY’, ‘mycustomstring’);
`
in your template file:
`
<!–mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> –>
echo do_shortcode(‘[wt_geotargeting get=”city”]’);
<!–/mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> –>
`
You probably copied the code from someone I also found when using Google. He suggests to use rand(), which is not correct and causes issues.
@fistfullofcrisco The code you want to run dynamically should never be between PHP-tags, otherwise it won’t be dynamic as the PHP code will compile before the page is cached, defeating the purpose of page fragment cache. Also your suggestion might be “typically used”, but we actually support multiple implementations. Check our wiki for more details: https://github.com/Auctollo/w3-total-cache/wiki/FAQ:-Developers#how-do-i-implement-page-fragment-caching