How to disable cache for the content returned by a shortcode

we have wrote a shortcode that returns a different content based on a timestamp.

The typical business case is: "Before the 1st of January, display "registrations will be open on the 1st of January" and after that date "register here""

Therefore, it is quite important that this piece of content does not get cached.

Is there a way, from the shortcode code to indicate that this piece of content should not get cached (knowing that the cache mechanism is not yet chosen - nginx, memcache, total cache, ...)?

Topic plugin-wp-supercache shortcode plugin-w3-total-cache cache Wordpress

Category Web


As the caching usually doesn't work on parts of the page, but on the whole page, you can't have it just not cache that specific part (well, you could use ESI/Edge Side Includes, but that's not an option for all implementations).

What you could to is write a hook that checks whether these shortcodes are used and adjust headers indicating that it might not be cached or only cached up to X seconds (with the indicated max lifetime falling on the date and time you want to show the changed content).

Or you could parse the shortcodes when posts are updated and add WP cronjobs that will silently update the post. You'll most likely have some sort of purging mechanism in your cache implementation that removes the cached result if the post is updated.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.