Enqueued Stylesheet Version Number Not Being Appended

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);

1 Answer
1

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.

Leave a Comment