A collection of small code snippets and helper plugins that make the WP Media crew's life easier.
Important
These snippets target specific use cases and may require manual configuration. Review the linked code or README, test it on a staging site, and confirm compatibility with your versions of WordPress, WP Rocket, and any related plugins before using it in production.
| Name | Description / use case |
|---|---|
| Prevent Cache Generation for Active Carts | Prevents a WooCommerce request with an active-cart cookie from generating a public cache file, while still allowing an existing neutral cache file to be served. |
| Disable Cache Generation for a Dynamic Cookie | Prevents cache generation when a configured dynamic cookie is present while preserving other WP Rocket optimizations. Useful for server-rendered, cookie-dependent content. |
| Force Cache Lifespan | Immediately removes cache files older than a configurable age. Useful for manually enforcing a shorter cache lifespan. |
| Don't Cache the WordPress REST API | Prevents WP Rocket from caching REST API requests, particularly for affected multisite configurations. |
| Cache Only Specific Pages for Logged-in Users | Limits logged-in-user cache generation to a configurable set of pages or posts. |
| Optimize WooCommerce Pages Without Caching | Applies WP Rocket optimizations to checkout, cart, and account pages while keeping page caching disabled. |
| Name | Description / use case |
|---|---|
| Prevent Query-string Root Purges | Removes root URLs containing query strings from automatic post-purge lists so they cannot resolve to the domain cache root. |
| Filter Domains Used for Cache Clearing | Filters the domain URLs passed to rocket_clean_domain(). Useful for Bedrock or custom cache-directory configurations. |
| Prevent Recursive Folder Cleanup | Protects configured language or section folders from recursive cache deletion and removes only their index cache files. |
| Safe Post Cache Purge on Status Change | Avoids fatal errors when third-party code calls pre_post_update with invalid data, while preserving an appropriate cache purge. |
| Remove Additional URLs from Post Purges | Stops additional related URLs from being included in WP Rocket's automatic purge when a post is updated. |
| Remove Additional URLs from Product Purges | Stops additional related URLs from being included in WP Rocket's automatic purge when a WooCommerce product is updated. |
| Disable Cache Clearing for Terms | Disables WP Rocket's automatic cache clearing when taxonomy terms are created. |
| Clear Additional Domains | Adds parked or alternate domains to WP Rocket's domain-wide cache-clearing list. |
| Clear Cache After a Breakdance Save | Clears a post's cache after the Breakdance builder saves the document. |
| Clear Cache After a TotalPoll Vote | Clears a post and configured related URLs after a new TotalPoll vote is cast. |
| Clear Cache After a KK Star Ratings Vote | Clears the affected post cache after a visitor submits a KK Star Ratings vote. |
| Clear Cache After WordPress or Plugin Updates | Clears the entire WP Rocket cache after a plugin update or successful WordPress core update. |
| Clear a CPT Mobile Archive | Adds a configurable set of custom-post-type mobile archive URLs to the purge triggered by a post update. |
| Clear Cache When Files Change | Cron-friendly script that clears cache, Used CSS, and/or minified files when configured CSS or JavaScript files change. |
| Reset Multisite Cache Tables After Cleanup | Marks multisite cache-table rows as pending after cleanup so preload can rebuild erased subsite caches. |
| Name | Description / use case |
|---|---|
| Reset the Cache Table | One-time helper that truncates the cache table, clears cache, and restarts preload from sitemap URLs. |
| Exclude Attachment URLs from Preload | Keeps WordPress attachment URLs out of the cache table and preload process. |
| Exclude Out-of-stock Products from Preload | Prevents out-of-stock WooCommerce product URLs from being added to preload. |
| Exclude Products in a Category from Preload | Prevents products in configured WooCommerce categories, such as sold-out, from being preloaded. |
| Exclude URLs from the Cache Table When Preload Is Disabled | Keeps visited URLs out of the WP Rocket cache table when preload is turned off. |
| Filter Preload Links | Adds configured URL patterns to the browser preload-links exclusion list. |
| Change the Preload User Agent | Customizes the user-agent string sent by WP Rocket preload requests. |
| Tune Preload and RUCSS Parameters | Adjusts preload and Remove Unused CSS batch sizes, cron intervals, and delay between requests to reduce server load. |
| Performance Tweaks for Preload and RUCSS | Packaged tuning helper for lowering preload/RUCSS CPU load and rejecting suspiciously small Used CSS results. |
| Show the Cache Generation Source | Adds an HTML comment showing whether a page was cached by preload or by a regular visit. |
| Name | Description / use case |
|---|---|
| Preserve All Styles from Remove Unused CSS | Preserves every inline style and stylesheet from Remove Unused CSS processing. Useful as a broad diagnostic or temporary workaround. |
| Exclude Inline CSS by Attribute from Remove Unused CSS | Preserves configured inline styles whose id or class attributes must not be removed. |
| Clear Used CSS After a Theme Update | Triggers Used CSS regeneration after a WordPress theme is updated. |
| Regenerate Critical-path CSS | Standalone script that starts Critical-path CSS regeneration for the legacy asynchronous CSS feature. |
| Clear Minified Files After an Elementor Draft Save | Clears minified CSS and JavaScript cache when an Elementor draft is saved. |
| Programmatically Exclude Scripts from Delay JavaScript | Adds JavaScript files to Delay JavaScript exclusions through code instead of the WP Rocket settings field. |
| Remove Scripts from Automatic Delay JavaScript Exclusions | Allows configured scripts to be delayed even when WP Rocket or an integration excludes them automatically. |
| Delay the WooCommerce Product Gallery | Overrides the WooCommerce product gallery's automatic Delay JavaScript exclusion. |
| Disable Delay JavaScript by Device Type | Disables Delay JavaScript on either mobile or desktop when separate mobile cache is active. |
| Find Inline JavaScript | Browser-console utility that lists external, delayed, and inline scripts to help identify JavaScript for exclusions or debugging. |
| Name | Description / use case |
|---|---|
| Clear Critical Images Data | Standalone script that clears Optimize Critical Images data and related cache so it can be regenerated. |
| Disable Optimize Critical Images for Post Types | Disables Optimize Critical Images on configured post types, such as WooCommerce products. |
| Clear Related Optimized Critical Images | Deletes Optimize Critical Images records for URLs related to a post or term purge. |
| Clear Priority Elements | Standalone script that clears Priority Elements data and cache for regeneration. |
| Name | Description / use case |
|---|---|
| Purge Cloudflare via Cache Lifespan | Synchronizes cache-lifespan purges with Cloudflare APO or Cache Everything through the official Cloudflare plugin. |
| Disable Automatic Cloudflare Cache Clearing | Stops WP Rocket from automatically clearing Cloudflare when the official Cloudflare plugin is active. |
| Clear and Preload Cache from ManageWP | ManageWP PHP snippet that bootstraps WordPress, clears WP Rocket cache, and triggers preload. |
| Resync Elementor Library Cache | Clears cache and triggers preload when a purged URL belongs to the Elementor template library. |
| Clear WPML Product Translations | Clears translated WooCommerce product caches when the main-language product is updated, including setups with translated slugs. |
| Disable Contact Form 7 Optimization | Disables the compatibility optimizations WP Rocket applies to Contact Form 7. |
| Filter WP Rocket HTTP Request Arguments | Adjusts outbound HTTP request arguments used for WP Rocket license validation. |
| Name | Description / use case |
|---|---|
| Count Cache Files | Lists and counts compressed HTML cache files for the current domain. |
| Export WP Rocket Settings | Standalone script that downloads the wp_rocket_settings option as JSON when normal admin export is unavailable. |
| Export WP Rocket Settings (alternate) | Alternate standalone settings exporter for cases where the WordPress backend cannot be accessed. |
| Send a Direct RUCSS API Request | Sends a configurable cURL request directly to the Remove Unused CSS SaaS for connection testing and troubleshooting. |
| Varnish Debugger | Web form for sending configurable PURGE or BAN requests to a Varnish endpoint and inspecting the HTTP response. |
Remove Last-Modified from .htaccess Rules |
Removes WP Rocket's Header unset Last-Modified directive when regenerating .htaccess. |
| Enable Cache and Optimizations for Additional Taxonomies | Removes WP Rocket's default restrictions for taxonomies it does not consider valid, allowing their pages to be cached and optimized. |
| Disable the Rocket Insights Promotion Notice | Removes the Rocket Insights promotional admin notice registered by WP Rocket. |
| Reset the RocketCDN CTA | One-time helper that removes the per-user flag hiding the RocketCDN call to action. |