I've been breaking my head on this one. I have a child theme and made changes to the style.css
document. These changes did not show up in the reload of the page because there is no mention of version in the stylesheet declaration of this file.
I have found out that style.css
is loaded as a foundation of the theme and that the version number in the header of style.css
is supposed to show up, but it doesn't. I've tried the deregister, dequeue and requeue options that I found online, but still no go.
I have made a work around by queueing another css file for which I have added versioning based on the modification date of the file, but I am curious if others have seen this issue and have a proper solution.
I've been breaking my head on this one. I have a child theme and made changes to the style.css
document. These changes did not show up in the reload of the page because there is no mention of version in the stylesheet declaration of this file.
I have found out that style.css
is loaded as a foundation of the theme and that the version number in the header of style.css
is supposed to show up, but it doesn't. I've tried the deregister, dequeue and requeue options that I found online, but still no go.
I have made a work around by queueing another css file for which I have added versioning based on the modification date of the file, but I am curious if others have seen this issue and have a proper solution.
Share Improve this question edited Dec 30, 2019 at 8:40 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Dec 30, 2019 at 8:07 klskls 218 bronze badges2 Answers
Reset to default 1Are you sure the version is included in style.css
in the right way? In that case this should really work (hook with wp_enqueue_scripts
):
$theme_data = wp_get_theme();
wp_register_style('your-style-handle', get_template_directory_uri() . '/style.css', '', $theme_data['version'], 'all');
wp_enqueue_style('your-style-handle');
While developing you may not want to change the file version in style.css
all the time, in which case you could use filemtime( get_template_directory_uri() . '/style.css' )
in stead of $theme_data['version']
in above code. Codewise that would be the proper thing to do. Otherwise, beware of browser cache issues.
Call me silly, but just found a way of getting it enqueued without having it as duplicate. @cjbj, I do really appreciate your help!
If you enqueue it in the child theme's function.php
file (at the end of the stylesheets enqueued in there for priority sake) and make sure you use the exact same handle as the theme is registering it with (look it up in the source code of the page, but without the -css
at the end), then WP will see it as already registered by the time the theme is trying its standard registration and ignore that. Using filemtime()
for versioning works perfectly:
wp_enqueue_style( 'theme stylesheet specific handle', get_stylesheet_uri(), array(), filemtime(get_stylesheet_directory() . "/style.css" ) );