All Collections
Features and Optimizations
Can I Exclude a Shortcode From the Cache?
Can I Exclude a Shortcode From the Cache?
Updated over a week ago

When using NitroPack, it is not possible to exclude a shortcode from optimization and from caching. This is because shortcodes require fragment caching, which we do not currently support.

NitroPack uses page caching that caches the entire output of the page. This means the PHP code will only get processed further if there is a cache purge for the page/website.

Additional information about this can be found in our article:

If the shortcode uses PHP for dynamic actions, it won’t be possible to exclude the shortcode itself from caching.

📍But there are a couple of other solutions:

1. Exclude pages from caching

You can exclude the affected pages from being cached as per our guide:

Excluding the pages from optimizations will halt all NitroPack optimizations on them; however, the shortcodes will work as expected, and the information will continuously be up-to-date.

*We recommend this method if there are only a few affected pages.

2. JavaScript/AJAX compatibility

Check if the plugin you’re using for the shortcode has a JavaScript/AJAX compatibility option and enable it:


💡If you cannot find such an option, we recommend checking with the plugin’s support team whether they are compatible with caching.

This will resolve the issue and works well with caching solutions such as NitroPack.

In case you are using shortcodes in Widgets, you could use a plugin to transform them into AJAX widgets, such as this one:

⚠️ The above solution for Widgets is only for WordPress websites.

3. (WordPress specific) Automatically purge pages at set intervals

You can purge the cache for pages automatically by using WP-CLI along with a Cron Job.

To achieve this, use our guide:

This way, if the pages’ content gets updated more frequently, you can set a cron job to purge the cache automatically, resulting in updated information on the pages.

📌 If you need any assistance or have questions, reach out to our support team at [email protected] or via this link:

Did this answer your question?