Created
October 28, 2015 14:04
-
-
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.
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
// 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