Add Theme/Plugin-Version to URL not the WP-Version
|Reported by:||Drivingralle||Owned by:|
If a theme- or plugin-developer doesn't provide the argument for the version number while using any enqueue-function (wp_enqueue_style, wp_enqueue_script) WP adds it's own version number to the URLs.
This leads to the problem:
A theme is updated, adding new styles including some changes to the generated HTML. If WP is not updated at the same time, browser and proxies will not re-download the file. This can break layouts because of the lack of updated stylesheet.
The same goes for plugins.
And if WP is updated all scripts and styles are re-downloaded. Which is not required.
I would like to see the following behavior:
If the version argument is set, use it.
No Argument, use the fallback:
- Styles/scripts enqueued by the theme get the version number of the theme.
- Styles/scripts enqueued by a plugin get the version number of the plugin.
- Files enqueued by/from core should still use the core version (e.g. jQuery).
I use this code in my themes. So there is a variable for the theme version.
// Save same data about the theme into a variable $my_theme_data = wp_get_theme(); // Enqueue a CSS style file wp_enqueue_style( 'child_style', get_stylesheet_directory_uri() . '/style.css', array(), $my_theme_data->Version );
- how to detect if theme, plugin or core is enqueuing the file
- how to get the version number of a plugin
- what to do if a plugin and a theme or two plugins are enqueued with the same handle
Aside thought on it:
Adding the version of WP and the theme to the stylesheet-url or maybe a hash of it. Woldn't solve it for plugins ...
Change History (8)
3 years ago
- Component changed from Media to Script Loader
- Keywords 2nd-opinion added