Wordpress Bones Theme CSS and JS Versioning

I have a website that was built using the bones wordpress theme. No matter what I do, I cannot get version control to work with css and js using wordpress enqueue features.

Is there something in the bones, maybe a filter that I can't find that robs the version?

Any suggestions are greatly appreciated.

thank

+3


source to share


2 answers


You are probably in luck that it doesn't exist by default, most people try to remove it as it defaults to the Wordpress version number (why?).

I found the best way to add this is to add the my_wp_default_styles function to your .php functions. Also a neat trick is to check the last modified date of the main css file and make that version timestamp.



function my_wp_default_styles($styles) {
  $styles->default_version = filemtime(get_template_directory() . '/style.css');
}
add_action("wp_default_styles", "my_wp_default_styles");

      

+1


source


I found him!

There's a filter in the Bones theme that removes all CSS / JS versions.

Just look in the file bones-theme/library/bones.php

, you got the filter function



// ~L.48
add_filter( 'style_loader_src', 'bones_remove_wp_ver_css_js', 9999 );

/** Some code **/
// ~L.89
function bones_remove_wp_ver_css_js( $src ) {
  if ( strpos( $src, 'ver=' ) )
        $src = remove_query_arg( 'ver', $src );
  return $src;
}

      

You can either edit it or just remove the hook and put your version in the wp_enqueue_script () / wp_enqueue_style () functions.

+1


source







All Articles