Disable WP Rocket page cache only
- WP Rocket
WP Rocket ties optimizations with page cache.
But it’s possible to disable page cache either site wide or specific pages when needed.
It’s done using the do_rocket_generate_caching_files filter as follow:
<?php
/**
* Disable WP Rocket Page Cache (Site-Wide)
*
* Disables HTML page caching while keeping all other WP Rocket optimizations
* active (JS/CSS minification, lazy loading, preloading, etc.). Useful when
* you need another caching layer (e.g. Cloudflare, Varnish) to handle HTML
* caching but still want WP Rocket's optimization features.
*
* Usage: Add to functions.php or a custom plugin.
*
* @category wp-rocket
* @language php
*
* @author Adame Dahmani https://adame.io
* @support Support my family project: https://adame.io/fundraiser
*/
add_filter( 'do_rocket_generate_caching_files', '__return_false' );It’s also possible to use it with a condition.
This is an example of how to use the filter to exclude pages with specific IDs from page cache:
<?php
/**
* Disable WP Rocket Page Cache (Conditional)
*
* Excludes specific pages or posts from WP Rocket's page cache by ID.
* All other pages remain cached normally. Useful for dynamic pages
* (account, cart, checkout) that should never be served from cache.
*
* Usage: Add to functions.php. Replace the IDs in $excluded_ids with your own.
*
* @category wp-rocket
* @language php
*
* @author Adame Dahmani https://adame.io
* @support Support my family project: https://adame.io/fundraiser
*/
function snippet_exclude_from_page_cache( $filter ) {
$excluded_ids = array( 1, 2 );
if (
( function_exists( 'is_page' ) && is_page( $excluded_ids ) ) ||
( function_exists( 'is_single' ) && is_single( $excluded_ids ) )
) {
return false;
}
return $filter;
}
add_filter( 'do_rocket_generate_caching_files', 'snippet_exclude_from_page_cache' );