2

I have an issue with the child theme stylesheet being browser cached, and I need to dequeue/reregister, then re-enqueue with a timestamp for the version number. The dequeue then re-enqueue is working fine, but no matter what I try there isn't a version number being appended. I've tried to set the version parameter of wp_enqueue_style() to both true, and a string. No matter what there isn't a version number added as a query string to the stylesheet link href. My full code snippet is below.

function custom_dequeue_enqueue_child_styles() {

    wp_dequeue_style('mk-style');
    wp_deregister_style('mk-style');

    $cacheBuster = filemtime(get_stylesheet_directory() . '/style.css');

    wp_enqueue_style('jupiter-child-stylesheet', get_stylesheet_directory_uri() . '/style.css', array(), $cacheBuster, 'all');

}

add_action( 'wp_enqueue_scripts', 'custom_dequeue_enqueue_child_styles', 999999999);
  • Nobody can put a possible answer on this? – AndyWarren May 10 '17 at 21:34
  • 1
    Your code is pretty much the same as what I use to include a version number. My guess is something else is affecting it - do you have a caching plugin, or CSS concatenating plugin, or something like that? If you disable all plugins does it then show the version number? – WebElaine May 10 '17 at 22:03
2

As it turns out, the code does indeed work, and the reason the version number was being stripped out was due to a buried theme option that by default removes all version numbers from all JS and CSS files.

This is in the Jupiter WordPress theme by Artbees, and the theme option is in Theme Options > Speed Optimization > Query Strings from static Files. By default its set to "off" and that removes version numbers. Setting it to "On" appends version numbers as query string parameters. This is a very dumb option to be enabled by default, but now we know.

  • 1
    Thanks for pointing me in the right direction. I was working on a theme I inherited from someone else, and wasn't aware that soil (roots.io/plugins/soil) was being used to disable script versioning. – James Beninger Apr 15 '18 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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