wordpress enqueue script cache busting

Solutions on MaxInterview for wordpress enqueue script cache busting by the best coders in the world

showing results for - "wordpress enqueue script cache busting"
Maxine
09 Jan 2019
1function my_load_scripts($hook) {
2 
3    // create my own version codes
4    $my_js_ver  = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/custom.js' ));
5    $my_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ));
6     
7    // enqueue
8    wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), $my_js_ver );
9    wp_register_style( 'my_css',    plugins_url( 'style.css',    __FILE__ ), false,   $my_css_ver );
10    wp_enqueue_style ( 'my_css' );
11 
12}
13add_action('wp_enqueue_scripts', 'my_load_scripts');
14
15// Note: Replace 'plugin_dir_path' with "get_stylesheet_directory_uri() . '/[filename].css'" for theme or child theme dir paths.