Hide Plugin and Theme Versions in Asset URLs
Replaces the ?ver= value on plugin and theme CSS and JavaScript files with a short hash, so scanners cannot read your exact plugin versions from the page source, while caches still refresh whenever a version changes.
Opens WPIDE on
Code
$wpide_hash_version = function ( $src ) {
if ( ! is_string( $src ) || false === strpos( $src, 'ver=' ) || false === strpos( $src, '/wp-content/' ) ) {
return $src;
}
$query = (string) wp_parse_url( $src, PHP_URL_QUERY );
parse_str( $query, $args );
if ( empty( $args['ver'] ) ) {
return $src;
}
return add_query_arg( 'ver', substr( wp_hash( $args['ver'] . '|' . strtok( $src, '?' ) ), 0, 8 ), $src );
};
add_filter( 'style_loader_src', $wpide_hash_version, 9999 );
add_filter( 'script_loader_src', $wpide_hash_version, 9999 );
Notes
Plugin readme files can still reveal versions; block access to readme.txt files on your server for full coverage.
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.