Removing WordPress Version Number from Source Code
Custom Code Solution
The WordPress version number appears in two places in your source code:
- As a meta tag generator
- In CSS and JavaScript file URLs
Here's a complete solution to remove both:
Add this code to your theme's functions.php
file:
This function removes the WordPress version from the head section and RSS feeds:
function remove_wp_version() {
return '';
}
add_filter('the_generator', 'remove_wp_version');
This function removes version numbers from CSS and JavaScript files:
function remove_version_from_scripts($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'remove_version_from_scripts', 9999);
add_filter('script_loader_src', 'remove_version_from_scripts', 9999);
Combined Solution
Here's both functions combined into a single, ready-to-use code block:
function hide_wp_version_numbers() {
// Remove version from head
add_filter('the_generator', function() { return ''; });
// Remove version from scripts and styles
function remove_version_from_scripts($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'remove_version_from_scripts', 9999);
add_filter('script_loader_src', 'remove_version_from_scripts', 9999);
}
add_action('init', 'hide_wp_version_numbers');
Where to Add the Code
- Add the code to your theme's
functions.php
file
- If using a child theme (recommended), add it to the child theme's
functions.php
- Alternatively, create a site-specific plugin for this functionality
Plugin Solutions
If you prefer using a plugin, here are reliable options:
-
Hide My WP Ghost - Security plugin with version number hiding
-
Security Headers - Includes version number removal
-
Perfmatters - Performance plugin with security features including version number removal
Important Notes
- Removing version numbers is a basic security measure but shouldn't be your only security implementation
- Keep WordPress, themes, and plugins updated regularly
- Test your site after implementing these changes to ensure nothing breaks
- Consider implementing additional security measures alongside version number removal