WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In header.php, I like to attribute a version number to the stylesheet so that the browser gets forced to refresh it. But when working with a child theme, its stylesheet is not explicitely called, rather WordPress automatically seeks it. So how or where to attribute a version number to the child theme's stylesheet?

share|improve this question
up vote 1 down vote accepted

You can update the version in the child themes style sheet itself...

 Theme Name:   Twenty Fourteen Child
 Theme URI:    http://example.com/twenty-fourteen-child/
 Description:  Twenty Fourteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfourteen
 Version:      1.1.2 <---- Update here
share|improve this answer
Are you positive that this will necessarily flush any cached stylesheet and force the new version to be loaded, just as when adding a version number in header.php? – drake035 May 30 '14 at 10:35
Yes, if you look at the page source you will see the query string updated as you change the version number within your child themes style.css – Matt Royal May 30 '14 at 11:36
Awesome. Did I start a bounty for this question? Matt let me know, if so I'll start it again and grant it to you. Thanks! – drake035 Jun 10 '14 at 11:59
@drake035 You did, yes. That would be great, thanks man :-) – Matt Royal Jun 10 '14 at 13:37
It depends how your theme has been setup. Look down the page @kraftner answer. If your theme is de-registering and then re-registering the file then this wont work. – Matt Royal Apr 18 '15 at 8:24

I think the best way to do this is to leave the child theme stylesheet (style.css) empty with only the necessary comments (like theme name, description etc, so can wordpress recognize your theme) and then make another css file in your-theme-name-folder/css/main.css

After that on function.php you can have a new "version" every time you change your file :

function my_scripts_and_styles(){

$cache_buster = date("YmdHi", filemtime( get_template_directory_uri() . '/css/main.css'));
wp_enqueue_style( 'main', get_stylesheet_directory_uri() . '/css/main.css', array(), $cache_buster, 'all' );


add_action( 'wp_enqueue_scripts', 'my_scripts_and_styles', 1);

The logic:

Every time you save the file the modified time of the file is being changed. The new time is being passed to date function to convert the time(filemtime returns an integer representing the time) to date format to make it a string in the format you desire. In our example the time is being formatted with accuracy of minutes. You can change it to track even second ie "YmdHis".After that the new modified time of the file is being passed as a new version to wp_enqueue_style.

Reference :



share|improve this answer
I prefer using the theme version as cache buster. If you use $cache_buster = wp_get_theme()->get('Version') you'll get the version specified in the comment block in style.css. See codex.wordpress.org/Function_Reference/wp_get_theme for reference. – Marcel Stör Jan 2 at 14:45
Nice didn't know the existence of this function. But again you have to change manually the version every time you make a change and it can be frustrated especially when developing (given cache issues). Also you are obligate to code in style.css even if you import your main.css file there, which btw I don't find it a good approach. Furthermore if you code in SASS it can be again difficult to maintain it. Finally I think is faster to check the file time than opening the file , reading the first comments and finding the version (I am not sure if wp_get_theme()->get('Version') works that way ). – Laxmana Jan 4 at 19:18
True, but on the positive side you get better control over your styles. You can update the CSS incrementally and when you're satisfied with the result you can finally bump the version and "release" it. – Marcel Stör Jan 4 at 19:28

I believe that if you use the Wordpress theme editor to edit your child theme's stylesheet that it automatically appends a new version number each time you save the file.

share|improve this answer
Right but I don't use the WP editor to work on my stylesheets.. – drake035 May 26 '14 at 18:23

Instead of using the default style.css I typically use wp_enqueue_style in the child theme's functions.php or another included php file. So, you'd still have the style.css in the child theme with all the child theme details but then you can have a separate css file in the child theme for the actual child theme styling (I usually put this in an assets/css directory within the child theme). This would also allow you to set the CSS version with the 4th parameter. For example:

function theme_name_child_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_directory_uri() . '/assets/css/child-style.css', array(), '1.0.0', 'screen');

add_action( 'wp_enqueue_scripts', 'theme_name_child_scripts' );

You can add a priority to the action if it's not loading in the correct order or work with the dependency parameter in wp_enqueue_style above:

add_action( 'wp_enqueue_scripts', 'theme_name_child_scripts', 20 );
share|improve this answer

What you need to do is de-register the main style which has the handle style-css and then re-register with your version number:

Put this in the function.php of your child-theme:

function wpse_145141_change_style_version(){
    // First de-register the main stylesheet
    wp_deregister_style( 'style-css' );
    // Then add it again, using your custom version number
    wp_register_style( 'style-css', get_stylesheet_uri(), array(), "VERSION_NUMBER" );
    //finally enqueue it again
    wp_enqueue_style( 'style-css');

add_action( 'wp_head', 'wpse_145141_change_style_version');
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.