Remove WordPress Version Number from HTML Source

Luca B Dec 24, 2024 Security
How can I hide the version number of my WordPress site from appearing in the code?
What is the best method to remove the WordPress version number from the HTML source code for enhanced security?
Andy answered Dec 24, 2024

Remove WordPress Version From HTML Source

Custom Code Solution

Add this code to your theme's functions.php file or a custom plugin:

Remove WordPress version number from various locations:

function remove_wordpress_version_number() {
    return '';
}
add_filter('the_generator', 'remove_wordpress_version_number');

Remove version from CSS and JS files:

function remove_version_from_styles_scripts($src) {
    if (strpos($src, 'ver=')) {
        $src = remove_query_arg('ver', $src);
    }
    return $src;
}
add_filter('style_loader_src', 'remove_version_from_styles_scripts', 9999);
add_filter('script_loader_src', 'remove_version_from_styles_scripts', 9999);

Remove version from RSS feeds:

function remove_version_from_rss() {
    return false;
}
add_filter('do_feed_rss2_comments', 'remove_version_from_rss', 1);
add_filter('do_feed_rss2', 'remove_version_from_rss', 1);

What These Code Snippets Do

  1. First snippet removes the meta generator tag that shows WordPress version
  2. Second snippet removes version numbers from CSS and JavaScript files
  3. Third snippet removes version information from RSS feeds

Plugin Solutions

If you prefer using a plugin, here are reliable options:

  1. Hide My WP Ghost - Premium security plugin with version number removal
  2. Security Headers - Free plugin that includes version number removal

Additional Security Tips

  • Keep WordPress core, themes, and plugins updated
  • Use strong passwords and limit login attempts
  • Consider using a security plugin for additional protection
  • Regularly backup your website
  • Use SSL certificate (HTTPS)

The custom code solution is the most lightweight approach and doesn't require additional plugins. Place any of these code snippets in your theme's functions.php file or in a site-specific plugin for better portability across themes.