Exclude all CSS files in a folder / directory from Load CSS Asynchronously
In rare cases the option Load CSS Asynchronously may conflict with a set of files, specially when they are being dynamically generated by one of your plugins or your theme.
If this option causes any problems, you may need to exclude a folder from the process. You can do that by downloading, editing, and installing the following small helper plugin.
📝 Manual code edit required before use!
You must edit the line beginning with $excluded_folders[]
to reflect the path of the folder you want to exclude.
📥 Download (.zip): WP Rocket | Exclude Folders from Async CSS
Developers: You can find the code for this plugin on GitHub.
To install the plugin, please follow these steps:
- Download the helper plugin zip file.
- Edit the PHP file, adding the folders and files you want to exclude (Follow the steps below)
- Install the helper plugin on your site - go to Plugins → Add New → Upload plugin and select the zip file.
- Activate the plugin
- Clear the WP Rocket cache
- If you have Minify CSS files option enabled, you will also need to add the same folder list to the Excluded CSS Files text area and save the settings but adding
/(.*)
at the end of every folder path (Follow the steps below).
Editing the PHP file
You can add one or mutiple folders, adding the path of a folder will exclude everything in the folder and subfolders.
This: /wp-content/themes/example-theme
is equivalent to a wildcard exclusion: /wp-content/themes/example-theme/(.*)
(Please don't add the (.*)
at the end of the line, just the path of the folder).
Excluding one folder
$excluded_folders[] = '/wp-content/themes/example-theme/assets/css';
Excluding multiple folders
You can exclude multiple folders by adding new lines with the path of the other folders:
$excluded_folders[] = '/wp-content/themes/example-theme/assets/css'; $excluded_folders[] = '/wp-content/plugins/some-plugin';
Excluding specific files (not folders)
You can also use this plugin to exclude specific files to avoid using two plugins at the same time (This helper plugin plus Exclude files from Load CSS Asynchronously). This can be done in case you find other files that should be excluded, but you don't want to exclude a whole folder for it.
$excluded_files[] = '/wp-content/plugins/plugin-name/filename1.css'; $excluded_files[] = '/wp-content/plugins/plugin-name/filename2.css'; $excluded_files[] = '/wp-content/plugins/plugin-name/filename3.css';
You can find the line you must uncomment and edit at the end of the PHP file:
Exclude from CSS minify
If you are using CSS minify, you must exclude the same folders and files from that option too.
Remember to add the /(.*)
at the end of the path for folders:
If you also excluded specific files from Load CSS Asynchronously, you must also exclude them from minify, please see: