Hide the WordPress version
Removes the generator meta tag from the page head and RSS feeds.
remove_action( 'wp_head', 'wp_generator' );
add_filter( 'the_generator', '__return_empty_string' );
Licensed under GPL-2.0-or-later, provided as is. Review and test it before using it on a live site.
How it works
By default WordPress prints <meta name="generator" content="WordPress 6.x"> in the head of every page and adds the same line to RSS feeds. Scanners read it to find sites running an old version. The first line removes the tag from the head. The the_generator filter empties it everywhere else, feeds included.
What it doesn’t hide
- Version numbers in
?ver=on core CSS and JavaScript files. - The
readme.htmlfile in the site root.
Hiding the version makes you a less obvious target. It doesn’t protect an outdated site, so keep WordPress updated.
How to check it works
Open any page, view the source and search for generator. The WordPress line should be gone. Do the same on /feed/.
How to undo it
Remove the two lines.
How to add this snippet
- Copy the code above.
- Paste it at the end of your child theme’s
functions.php, in Appearance → Theme File Editor or over FTP. - Save, then open the site and check that everything works. If something breaks, remove the code.
Need more than one? Open this snippet in the builder, turn on the others you want and copy them as one functions.php, or download them as a small plugin.