0

Unless i use:

wp_enqueue_style( 'dazzling-style', get_template_directory_uri() . '/css/main.css?ver=', array(), rand(10,99999), 'all' );

Then everytime I visit my site, be it local or live, I see that the version is 4.1 and even though I upload a new stylesheet or js, the browser still sees that 4.1 version.

What's going on? Where is that 4.1 coming from?

4

4.1 is coming from your WordPress version.

Also you should not append ver= to the src manually but use the fourth parameter of wp_enqueue_style.

0
2

The solution is simple: Use the last time the file was changed as version number. You can use filemtime() (File Modified Time) on the path of the file. Example:

wp_enqueue_style(
    'your-handle',
    get_template_directory_uri().'/assets/style.css', # use plugin_dir_url( __FILE__ ) for plugins
    array( 'dependencies', ), # use [] for PHP 5.4+
    filemtime( get_template_directory().'/assets/style.css' ) # use plugin_dir_path( __FILE__ ) for plugins
);

This will append the UNIX timestamp as version number. And it will stay that way until you change your stylesheet again. That's the most convenient way I know of. It stays cached in browsers until there's a change. That btw works perfectly with stuff like watch and livereload tasks during development.

And if you ask (in the comments) why WordPress doesn't do that per default, then my answer would be ... "Uhm, well. WordPress."

1
  • Can't grasp why this is not the default behaviour in Wordpress.
    – xaviert
    Nov 28 '18 at 9:44
0

try to remove ?ver=

4.1 is coming from wordpress, by default it set's a wordpress version

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.