Force Page Caching


Most caching plugins for WordPress use a de facto standard to exclude pages from being cached: the  DONOTCACHEPAGE WordPress Core constant. If defined as true during a request, WP Rocket would not cache the page in question, but allow a regular database request to WordPress.

However, in some rare cases, that behavior needs to be overridden, and WP Rocket lets you do that. Here is how.

Overriding DONOTCACHEPAGE via Filter in WP Rocket

As handy as a commonly used constant like DONOTCACHEPAGE can come in, there may be cases where a site admin needs to override it in order to still get a specific request cached, no matter whether a third-party plugin has tried to employ the common constant for cache exclusion of a page.

WP Rocket has you covered in that case. All you need to do is pass true to a special filter in WP Rocket, and WP Rocket will ignore the DONOTCACHEPAGE constant.

add_filter( 'rocket_override_donotcachepage', '__return_true', PHP_INT_MAX );

Helper Plugin

The following helper plugin will help you easily override a DONOTCACHEPAGE constant and force WP Rocket's page caching:

📥   Download (.zip):  WP Rocket | Force Page Caching

Developers: You can find the code for this plugin on GitHub.

Heads up! Using the Force Page Caching Helper plugin will not override excluded pages in the Never Cache URL(s)Never Cache Cookies rules. or individual Never cache this page option on the pages.

Example: Cached Pages for Members

Let’s say, you use a membership plugin to serve specific content for logged-in users only. You would want to enable the User Cache option in WP Rocket in order to provide fast-loading, cached pages for your logged-in site members.

Some membership plugins define the DONOTCACHEPAGE constant for logged-in users, because a common use case would be to not serve static, but dynamic content to members.
In our example, however, you would only aim to deliver static content to your logged-in members, additional to what non-logged-in users would see. So you would need to override the DONOTCACHEPAGE directive set by the membership plugin in order for WP Rocket’s User Cache option to work properly.

In order to do so, you’d best use the helper plugin provided above.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.