Cannot get Child Theme to load latest version of style.css

I’m using a Child theme set up correctly. But I just cannot get changes in the Child theme style.css to be reflected in the site. Tried emptying the browser cache a million times and it doesn’t work!

I’v created child template files and they overide the parent ones fine.

I have noticed in view sourse it puts a version number on the end of the style sheet like this:-
style.css?ver=3.9.1 even though I have created no version!

In another site I created there is no versioning of the style sheet, so why is it being put in automatically when I don’t want it set.

How can I force it to use the most up to date version of the Child style.css file and not version it?

Here’s my site url:- http://www.peterswebservices.co.uk/

5 s
5

In twentyfourteen, try putting this in your child theme:

function add_require_scripts_files() {
 wp_enqueue_style('twentyfourteen-style', get_stylesheet_directory_uri().'/style.css', array(), '1.0.0', "all");        
}
add_action( 'wp_enqueue_scripts', 'add_require_scripts_files' );

This will replace the original stylesheet but with your own version. If you are using a different parent theme, look at the original wp_enqueue_style label for style.css and duplicate that label within your child theme. You will have to change 1.0.0 to another number each time you make a change (so it’s better for production environments where you don’t make changes that often).

To remove the version from scripts and styles all together try this:

// remove WP version tag from scripts and styles, best for dev environments
// by Adam Harley https://wordpress.org/support/topic/enqueueregister-script-remove-version
add_filter( 'script_loader_src', 'remove_src_version' );
add_filter( 'style_loader_src', 'remove_src_version' );
function remove_src_version ( $src ) {
  global $wp_version;
  $version_str="?ver=".$wp_version;
  $version_str_offset = strlen( $src ) - strlen( $version_str );
  if( substr( $src, $version_str_offset ) == $version_str )
    return substr( $src, 0, $version_str_offset );
}

Leave a Comment