Last active
March 14, 2019 03:43
-
-
Save mikeott/34800fd575b7ad5d538fff28405f6b17 to your computer and use it in GitHub Desktop.
WordPress plugin CSS cache buster (based on plugin version number)
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
/* | |
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