W3 Total Cache is one of the top and free caching plugins for WordPress with more than 1 million active installations. However, it needs correct setup on your site to cache the pages and work properly. You will easily get lost with hundreds of available settings under different sections. It is easy to make mistakes in setup which will impact the page speed and break your site’s layout. Especially when you are using lots of JavaScript on a page, then you should test the W3 Total Cache (W3TC) on your staging or testing site throughly before deploying in live site. Read on further when you find some pages are broken and want to exclude them from the caching.
Why Excluding Specific Pages and Directories?
There are many reasons to exclude specific page or directory from caching for proper loading. This depends on the theme and plugins you use on your site. Here are some of the popular cases you will have problem with W3 Total Cache plugin:
- When you have WooCommerce plugin, product and cart pages generally break with W3TC caching.
- Using header slideshow with jQuery or JavaScript will break with the caching and will not load properly especially on mobile devices.
- Blog carousel element which comes with most of the page builder plugins like WPBakery will not work properly with W3TC.
If you use a theme that heavily depends on jQuery, you need to disable the minification of JavaScript for the pages to load correctly. Fortunately, W3TC provides an option for excluding pages and directories with wildcard so that you can easily exclude them from caching.
Frustrated with W3 Total Cache setup, try WP Rocket premium plugin to speed up your website. You will be surprised with the minimal setup and increase in your site’s page speed score.
Exclude Pages and Directories from Caching in W3 Total Cache
Login to your WordPress admin panel and navigate to “Performance > Page Cache” section. Scroll down to the “Advanced” section and look for the option “Never cache the following pages”.
You will see the plugin already added few lines in the text box like below.
wp-.*\.php
index\.php
Enter the page URLs and directories inside the “Never cache the following pages” text box to exclude them from caching. Again, scroll down to bottom and click “Save Settings & Purge Caches” button to clear the old cache and save your changes.
How to Enter Page URL and Directories?
W3 Total Cache allows lot of ways to enter the page and directory that you want to exclude from caching. You can use the URL, directory name, wildcard and regular expression format. Make sure to follow the below guidelines while entering your details:
- Enter one entires per line, it could be a page URL or the directory.
- The URLs and the directories are entered as relative URLs to your domain. This means you need to ignore the site address and only enter the remaining part.
Here are some of the example exclusion rules you can enter:
Exclusion Format | Expected Result |
---|---|
/showcase* | Any content starting with /showcase after the domain name will not be cached |
/shop* | All shop pages will be ignored |
/demo/ | Only demo directory will be ignored |
/post-name/ | Only the mentioned post URL will not be cached |
/page-url/ | Only the mentioned page URL will not be cached |
Other Possibilities for Excluding Content from Caching
Besides excluding posts, pages and directories, W3 Total Cache plugin also allows few other possibilities. These options are available in the same “Advanced” section under “Page Caching” menu.
Excluding Posts with Specified Categories
You can exclude all the posts under specified category by mentioning the category slug in the text box “Never cache pages associated with these categories”. For example, if you have the category named “technology” then just enter the slug as “technology” without leading or trailing slash. The plugin will exclude all posts under the category “technology” from caching and users will view non-cached pages.
Excluding Posts with Specified Tags
Similar to categories, you can ignore the posts from caching based on tags. Remember to enter the tag slug without slashes.
Excluding Posts Based on Author
Enter the author names one per line in the box “Never cache pages by these authors”. This will exclude all posts from the specified author from caching.
Exclude Posts Based on Custom Fields
Custom fields are additional fields where you can store relevant data in WordPress. You can use the default WordPress custom fields available in Gutenberg or Classic Editor to add custom fields to your post and pages. Later, you can exclude the pages from caching based on the custom fields you have added in the editor. The format of the entry should be like “custom filed=value” as shown below.
Careful About Other Options
As mentioned, the problem with W3 Total Cache plugin is that you will easily get confused with the settings. Just below the “Never cache….” options, you will find few more options which are not relevant for excluding pages and in fact, they are for including in the caching.
- There is another option called “Cache exception list”. The plugin will cache any URL or directory you enter in this box regardless of whether you have excluded using one of the above exclusion methods. So, ensure to leave this box as it is when you are excluding pages from caching.
- Also the “Non-trailing slash pages” option is useful for including pages with no trailing slash for caching. Generally, you can use this to cache XML Sitemap and other files not having trailing slash in WordPress. So for excluding pages from caching, you should not enter the URLs or directories in this box.
- Finally, leave the “Specify page headers” section as it is which is also for caching pages and not for excluding.
4 Comments
Leave your reply.