The Dynamic Shortcodes Extension for W3 Total Cache enables you to choose certain shortcodes to keep dynamic, while the rest of the page is cached. This can be useful if you have shortcodes that display geo-localised content or time-based content e.g. eBay listings ending in the next 10 minutes, for example, but want to take advantage of W3TC’s page caching to speed up your website.
- Download version 2017-01-01 (for use with W3TC 0.9.5 and later)
- Download version 2016-06-02 (for use with W3TC 0.9.4.1 and earlier)
For an explanation of why caching can be problematic with dynamic content, and how dynamic caching / fragment caching (used by this extension) compares to other methods, please see this page: Differences between caching methods with Geo targeted content.
Version 0.9.5 of W3 Total Cache significantly changed the way extensions are handled. Instead of a Extensions folder within the W3TC plugin directory, extensions are installed the same way as normal plugins. After doing this you also need to activate the plugin / extension. Note that activating the extension from the WordPress plugin page doesn’t activate the extension, it just makes it so that the extension will be able to register itself with W3TC. Actual activation of the extension is done via the W3TC extensions page (see Using the extension).
As of W3TC 0.9.5.1, there is a bug in its page cache module that prevents cached content being served whenever a page contains dynamic content. To fix this, open w3-total-cache/PgCache_ContentGrabber.php and find line 249:
if ( $this->_set_extract_page_key( $mobile_group,
And change it to:
if ( !$this->_set_extract_page_key( $mobile_group,
(i.e. add an exlamation mark)
To install the extension, unzip it, then upload the contents to the W3TC plugin’s extension directory ( typically wp-content/plugins/w3-total-cache/extensions/ ). Note that depending on your unzip software, it may unzip the files into a folder with the same name as the zip. If so, it is the file and folder inside that folder that need uploading to the extensions directory.
Please deactivate the extension, install the new version, then reactivate the extension. You may want to clear the cache after activating the new version.
The extension requires several W3TC settings to work:
- On the W3TC General Settings page, under the Page Cache section, Page cache method should be set to Disk: Basic.
- On the Page Cache page, under the Advanced section, enable Late initialization.
- If you want the user to see the dynamic output of a shortcode whenever they refresh / revisit the same page, then you need to disable browser caching. This is unlikely to be needed for most people, but if you do need this, then go to the Browser Settings page. Find the HTML & XML section, and enable Set cache control header. Set the Cache Control policy to no-cache ("max-age=0, private, no-store, no-cache, must-revalidate").
On the W3TC Extensions page, activate the Dynamic Shortcodes extension. Then click on the Settings link underneath it. This brings you to the extension settings page, where you can select which shortcodes you wish to make dynamic.
After you’ve saved the settings, you’ll need to clear the W3TC cache so that pages will be cached with the dynamic shortcodes.
Some plugins don’t register the shortcode when you are viewing an admin page, hence the extension can’t find the shortcode to pick it up. In this case there is a field at the bottom of the shortcodes list, where you can manually type out the shortcode tag name(s) to make dynamic.
There could also be other reasons for a shortcode not showing up. If you find that some shortcodes are missing from the list, please let me know the theme / plugin that adds that shortcode, and the shortcode tag, and I’ll try to see why the shortcode isn’t being picked up by the extension.
The first thing to check is that you’ve cleared the W3TC cache, and also your browser’s cache, to ensure you’re looking at a page where the dynamic shortcodes extension is active. Secondly, check that the shortcode works and is dynamic without W3TC page cache enabled, as the problem could be with the shortcode itself.
- Extensive modifications to enable the extension to work with W3TC 0.9.5 and above.
- Fixed a bug on the admin page where adding a shortcode(s) by text input and checking / unchecking shortcodes from the list only saved the new manually input shortcode(s).
- Fixed a bug where the plugin would try and process shortcodes for AJAX requests, which resulted in the shortcode not being processed correctly.
- If the extension can’t write to wp-config.php it will not activate and displays a (rather ugly) error message with the modification that needs to be made. Previously no error message would be shown and the extension would activate even when it couldn’t write to wp-config.php
- Added the option to manually enter shortcodes if they’re not listed on the extension settings screen. The extension can only ‘see’ shortcodes that are available in the admin area. Some plugins don’t register their shortcodes for pages in the admin area, so these shortcodes would not be available to choose from. With this update you can now add these shortcodes manually.
- Previously the extension didn’t work if you had HTML minification enabled in W3TC. Now it does.
- Initial version