Remove the Core Version From Script and Style URLs
Strips ?ver= from front-end CSS and JavaScript URLs when it equals the WordPress version, hiding it from the page source. Plugin and theme versions are left alone.
Opens WPIDE on
Code
$wpide_strip_core_version = function ( $src ) {
if ( ! is_string( $src ) || false === strpos( $src, 'ver=' ) ) {
return $src;
}
$query = (string) wp_parse_url( $src, PHP_URL_QUERY );
parse_str( $query, $args );
if ( isset( $args['ver'] ) && get_bloginfo( 'version' ) === $args['ver'] ) {
$src = remove_query_arg( 'ver', $src );
}
return $src;
};
add_filter( 'style_loader_src', $wpide_strip_core_version, 9999 );
add_filter( 'script_loader_src', $wpide_strip_core_version, 9999 );
Notes
After a WordPress update, browsers may keep cached core files a little longer.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.