I wanted to save the WordPress Customizer’s styles into an external stylesheet so it could be cached instead of having to load in the head of every page. I’m using this code to save the customizer’s styles to an external css file:
$css_filename = get_stylesheet_directory() . '/lib/css/customizer_styles.css';
file_put_contents( $css_filename, $css_string);
This stylesheet and the other default stylesheets are enqueued properly & in the correct cascading order (not imported or linked in the default style.css) & this is working perfectly on the front end, however when using the customizer, the changes now do not show up in the live preview. If you save changes they show up on the live site, but if you go back into the customizer, it’s still pulling a cached version of the css file before the changes were made. How do I force the customizer to refresh all enqueued stylesheets on it’s refresh?
To do so you need to enqueue your stylesheet and set
null
to the$version
parameter ofwp_enqueue_style