Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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/
<?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
You can’t perform that action at this time.