Skip to content

Instantly share code, notes, and snippets.

@mikeott
Last active March 14, 2019 03:43
Show Gist options
  • Save mikeott/34800fd575b7ad5d538fff28405f6b17 to your computer and use it in GitHub Desktop.
Save mikeott/34800fd575b7ad5d538fff28405f6b17 to your computer and use it in GitHub Desktop.
WordPress plugin CSS cache buster (based on plugin version number)
/*
Add custom stylesheet into plugin admin.
This method appends the plugin version number to the stylesheet for easy CSS cache busting.
If your plugin is at version 1.0 the styesheet URL will look like this:
https://example.com/wp-content/plugins/your-plugin/css/your-plugin-style.css?ver=1.0
Any time you update your plugin version number, the query string value will match it.
*/
function your_plugin_style() {
$plugin_data = get_plugin_data( __FILE__ );
$plugin_version = $plugin_data['Version'];
$plugin_directory = plugins_url('css/', __FILE__ );
wp_enqueue_style('your-plugin-style-admin', $plugin_directory . 'your-plugin-style.css', '', $plugin_version);
}
add_action('admin_enqueue_scripts', 'your_plugin_style');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment