Can I exclude a shortcode from the cache?
It's not possible to exclude the output of a shortcode from being cached. That would require fragment caching which WP Rocket doesn't support.
Page caching caches the entire output of the page. If your shortcode requires PHP to update its contents, it will not work with caching. The content will only be updated each time the cache is cleared.
Solutions / workarounds
- Use a solution which runs on JavaScript/AJAX - this will be compatible with caching and will always display the correct content.
- If the content is only displayed on a couple of pages, those pages could be excluded from the cache.
- In WP Rocket the only possibility is to reduce the Cache Lifespan to a lower value. This won't be perfect since the cache will only refresh at that specified interval, but the content will be less out-of-date.