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.
💡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.