Removes the WordPress version number from your site’s HTML head and RSS feeds. Exposing the version can help attackers target known vulnerabilities in outdated releases, so hiding it is a simple, low-effort security hardening step.
How to add it
- Open your child theme’s
functions.phpvia Appearance > Theme File Editor, or use a snippets plugin like WPCode (Code Snippets > Add Snippet > PHP Snippet). - Paste the code below at the bottom of the file or into the snippet box.
- Click Update File, or set the snippet to Active and click Save.
- Visit your homepage, right-click and choose View Page Source, then search for
generator. The WordPress version tag should no longer appear.
How it works
- By default, WordPress outputs a
<meta name="generator" content="WordPress x.x">tag in the page head through thewp_headaction, and also adds the version to RSS feeds. - The
the_generatorfilter controls the generator output everywhere it appears. - The function returns an empty string, so nothing is printed.
- A second filter strips the
?ver=query string from CSS and JS file URLs, which can also reveal the version.
/**
* Remove the WordPress version from head, feeds, and asset URLs.
*/
add_filter( 'the_generator', '__return_empty_string' );
/**
* Remove the WordPress version query string from scripts and styles.
*
* @param string $src Asset URL.
* @return string Modified asset URL.
*/
function my_remove_wp_version_from_assets( $src ) {
global $wp_version;
if ( strpos( $src, 'ver=' . $wp_version ) !== false ) {
$src = remove_query_arg( 'ver', $src );
}
return $src;
}
add_filter( 'style_loader_src', 'my_remove_wp_version_from_assets', 9999 );
add_filter( 'script_loader_src', 'my_remove_wp_version_from_assets', 9999 );
Tested on
WordPress 6.8
Reported by the author on November 23, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.5. It may still work.
