Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to load WordPress assets and append last modified time so the browser loads them only when necessary.
// the vhost has this line to define the environment 'SetEnv DEV_ENV development'
$suffix = empty($_SERVER['DEV_ENV']) ? '.min' : '';
wp_register_style('my-awesome-plugin', plugins_url("/assets/main{$suffix}.css", __FILE__), false,
filemtime( plugin_dir_path( __FILE__ ) . "/assets/main{$suffix}.css" ) );
wp_enqueue_script( 'jquery' );
wp_register_script( 'my-awesome-plugin', plugins_url("/assets/main{$suffix}.js", __FILE__), array('jquery', ),
filemtime( plugin_dir_path( __FILE__ ) . "/assets/main{$suffix}.js" ), true);
wp_enqueue_script( 'my-awesome-plugin' );
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.