Hide the WordPress version number
Remove the WordPress version from the generator tag, RSS feeds and ?ver= on scripts and styles, while keeping cache busting.
// Remove the generator tag from the page head and feeds.
add_filter( 'the_generator', '__return_empty_string' );
// Replace ?ver=<WordPress version> on scripts and styles with a site-specific hash.
function snipfire_hide_wp_version_in_urls( $src ) {
$query = wp_parse_url( (string) $src, PHP_URL_QUERY );
if ( ! $query ) {
return $src;
}
parse_str( $query, $args );
$version = get_bloginfo( 'version' );
if ( isset( $args['ver'] ) && $args['ver'] === $version ) {
// Still changes on every update, so browser caches refresh.
$src = add_query_arg( 'ver', substr( wp_hash( $version ), 0, 8 ), $src );
}
return $src;
}
add_filter( 'script_loader_src', 'snipfire_hide_wp_version_in_urls' );
add_filter( 'style_loader_src', 'snipfire_hide_wp_version_in_urls' );
What it does
WordPress prints its version number in a generator meta tag, in your RSS feeds and at the end of script and style URLs. Bots use it to find sites running older versions.
This snippet removes the generator tag and swaps ?ver= values that match your WordPress version for a short site-specific hash. The hash changes when you update, so browsers still fetch fresh files.
Good to know
- Hiding the version isn't a replacement for updating. Keep WordPress up to date.
- Also delete
readme.htmlfrom your site's root folder. WordPress adds it back with each update. - Admin pages still show the version, but only logged-in users can see them.