Conditionally Disable Remove Unused CSS
Sometimes you need to disable the Remove Unused CSS feature for groups of pages, based on their URLs slugs.
For example, if you want to disable the optimization on all product pages which are using the following structure:
https://www.example.com/products/wp-rocket-t-shirt/
You can use the string /products
to exclude all of them.
Helper plugin
The following helper will allow you to disable Remove Unused CSS for groups of URLs.
📥 Download (.zip): WP Rocket | Conditionally Disable Remove Unused CSS
Developers: You can find the code for this plugin on GitHub.
Heads up! Manual code edit is required before use!
Installation
To install the plugin please follow these steps:
- Download the helper plugin ZIP file.
- Customize the plugin's code:
Edit line 32, change/product
by a portion of the URLs where you'd like to disable RUCSS. All URLs that contain this string will be excluded. - To exclude multiple groups of URLs, you can duplicate line 32 as many times as needed. Each if condition should be followed by the
||
operator, except the last one. There is an example commented and ready to use on lines 36/47:
// MULTIPLE CONDITIONS if ( strpos( $url, '/product' ) !== false || strpos( $url, '/tag' ) !== false || strpos( $url, '/category' ) !== false || strpos( $url, '/size' ) !== false ) { add_filter( 'pre_get_rocket_option_remove_unused_css', '__return_zero' ); }<br>
- Install the helper plugin on your site - go to Plugins → Add New → Upload plugin and select the zip file.
- Activate the plugin
- Clear WP Rocket's cache