Im maintaining a wordpress site which uses GeneratePress theme. To extended a child theme solution was used. It is already a quite developed child theme (saying this to avoid dramatic solutions).
For a while I have had issues with CSS cache every time I update the CSS. style.css child stylesheets deliver the cache version instead of the modified one.
I believe that GeneratePress theme is loading parent style.css + child style.css if it exists.
generatepress/functions.php
// Enqueue our CSS.
wp_enqueue_style( 'generate-style-grid', get_template_directory_uri() . "/css/unsemantic-grid{$suffix}.css", false, GENERATE_VERSION, 'all' );
wp_enqueue_style( 'generate-style', get_template_directory_uri() . '/style.css', array( 'generate-style-grid' ), GENERATE_VERSION, 'all' );
wp_enqueue_style( 'generate-mobile-style', get_template_directory_uri() . "/css/mobile{$suffix}.css", array( 'generate-style' ), GENERATE_VERSION, 'all' );
wp_add_inline_style( 'generate-style', generate_base_css() );
// Add the child theme CSS if child theme is active.
if ( is_child_theme() )
wp_enqueue_style( 'generate-child', get_stylesheet_uri(), true, filemtime( get_stylesheet_directory() . '/style.css' ), 'all' );
Reading this piece of code... it seems that IF a child-theme is detected, it should already do the cache busting BUT... to me it does not. I dont get a url with filemtime result as a version param.
My child theme functions.php does not enqueue any 'style.css'. Despite of that it gets loaded after the parent style.css.
ATTEMPT 1 I have read the section for adding CSS from the generatepress https://docs.generatepress.com/article/adding-css/.
I don't see how to cache bust the child style.css file.
ATTEMPT 2 My first attempts to solve the issue has been based on enqueueing the stylesheet when wp_enqueue_scripts is triggered.
function theme_css(){
wp_enqueue_style( 'my-theme-style', get_stylesheet_directory_uri().'/style.css', 'generate-style', '1.1', 'all');
}
add_action( 'wp_enqueue_scripts', 'theme_css' );
I referred to generate-style since it seems to me that it is the parent default style to depend on (child style.css would load after the parent style.css). You can see this in the previous code snippet. It does not work for me. Child theme would load first and later the parent theme stylesheet. This is unfortunate and break the css. Order should be the contrary (parent style.css first and child style.css later). As said before, depending on generate-style does not help.
ATTEMP 3 Create the stylesheet with another filename. Generatepress complains since it needs a style.css stylesheet file if child_theme is detected. I could have a child theme with an empty style.css and the new stylesheet. The issue would be that style.css cache will be delivered for returning users.
Im somehow new to wordpress so I dont know other mechanism it could have to solve this. Maybe there is some easier solution that could work?