Last active
July 1, 2020 11:20
-
-
Save mishterk/0473fc07ff9a0c88e4cf8ae9f22a7f75 to your computer and use it in GitHub Desktop.
How to automatically version WordPress assets using their last modified time. More information at https://philkurth.com.au/tips/how-to-automatically-version-wordpress-assets-using-their-last-modified-time/
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 | |
add_action( 'wp_enqueue_scripts', function () { | |
$uri = get_stylesheet_directory_uri(); | |
$dir = get_stylesheet_directory(); | |
$script_last_updated_at = filemtime( "$dir/scripts/my-script.js" ); | |
$style_last_updated_at = filemtime( "$dir/styles/my-style.css" ); | |
wp_register_script( 'my-script', "$uri/scripts/my-script.js", [], $script_last_updated_at, true ); | |
wp_register_style( 'my-style', "$uri/styles/my-style.css", [], $style_last_updated_at, true ); | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment