Skip to content

Instantly share code, notes, and snippets.

@lordspace
Created October 28, 2015 14:04
Show Gist options
  • Save lordspace/b29949930646e42fd6df to your computer and use it in GitHub Desktop.
Save lordspace/b29949930646e42fd6df to your computer and use it in GitHub Desktop.
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_style('my-awesome-plugin');
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