Skip to content

Instantly share code, notes, and snippets.

@alpual
Last active October 5, 2020 23:29
Show Gist options
  • Save alpual/38c1a4e71c0be9eafa2959707659954e to your computer and use it in GitHub Desktop.
Save alpual/38c1a4e71c0be9eafa2959707659954e to your computer and use it in GitHub Desktop.
Wordpress Enqueue Scripts and Styles with timestamp
<?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');
@solaceten
Copy link

solaceten commented Oct 5, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment