Skip to content

Instantly share code, notes, and snippets.

@ediamin
Created March 13, 2020 02:55
Show Gist options
  • Save ediamin/4dc17d3521d2f338da0da16e5756cecc to your computer and use it in GitHub Desktop.
Save ediamin/4dc17d3521d2f338da0da16e5756cecc to your computer and use it in GitHub Desktop.
Using time() function in WordPress asset versioning for cache busting
<?php
namespace Vendor\Plugin;
class Assets {
// ...
public function register_scripts() {
$version = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? time() : MY_PLUGIN_VERSION;
wp_register_script( 'my-handle', MY_PLUGIN_ASSETS . '/js/script.js', [ 'jquery' ], $version, true );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment