Wordpress Bones Theme CSS and JS Versioning

狂风中的少年 提交于 2019-12-01 23:42:08

问题


I have a website that has been built using the bones wordpress theme. No matter what I do I can't seem to get versioning to work on css and js using the wordpress enqueue functions.

Is there something in bones, maybe a filter that I can't find that is stripping the versioning out?

Any suggestions are appreciated.

Thanks


回答1:


You're probably lucky that it's not there by default, most people try and remove it as it defaults to Wordpress version number (why?).

I found the best way to add it is to add the my_wp_default_styles function to your functions.php. Also a neat trick is to check the last modified date of the main css file and make that the 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");



回答2:


I found it !

There's a filter into Bones theme, which remove every CSS/JS versionning.

Just look into the bones-theme/library/bones.php file, you got a 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 place your versionning inside wp_enqueue_script()/wp_enqueue_style() functions.



来源:https://stackoverflow.com/questions/30389092/wordpress-bones-theme-css-and-js-versioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!