Answers for "wordpress enqueue script cache busting"

PHP
0

wordpress enqueue script cache busting

function my_load_scripts($hook) {
 
    // create my own version codes
    $my_js_ver  = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/custom.js' ));
    $my_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ));
     
    // enqueue
    wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), $my_js_ver );
    wp_register_style( 'my_css',    plugins_url( 'style.css',    __FILE__ ), false,   $my_css_ver );
    wp_enqueue_style ( 'my_css' );
 
}
add_action('wp_enqueue_scripts', 'my_load_scripts');

// Note: Replace 'plugin_dir_path' with "get_stylesheet_directory_uri() . '/[filename].css'" for theme or child theme dir paths.
Posted by: Guest on May-21-2021

Code answers related to "wordpress enqueue script cache busting"

Browse Popular Code Answers by Language