Last active
October 5, 2020 23:29
-
-
Save alpual/38c1a4e71c0be9eafa2959707659954e to your computer and use it in GitHub Desktop.
Wordpress Enqueue Scripts and Styles with timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_load_scripts($hook) { | |
// create version codes | |
$my_js_ver = date("ymd-Gis", filemtime( get_stylesheet_directory() .'/js/myscript.js' )); | |
$my_css_ver = date("ymd-Gis", filemtime( get_stylesheet_directory() . '/style.css' )); | |
wp_enqueue_script( 'my-script-name', get_stylesheet_directory() . '/js/myscript.js', array(), $my_js_ver ); | |
wp_register_style( 'my_css', get_stylesheet_directory() . '/style.css', false, $my_css_ver ); | |
wp_enqueue_style ( 'my_css' ); | |
} | |
add_action('wp_enqueue_scripts', 'my_load_scripts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using a parent theme directory
$my_js_ver = date("ymd-Gis", filemtime( get_template_directory_uri() .'/js/myscript.js' ));
get_stylesheet_directory() - when you are in a child theme