Remove WordPress Version Number
Remove WordPress version number from header and RSS feeds for better security
Code
1 // Remove version from head 2 remove_action('wp_head', 'wp_generator'); 3
4 // Remove version from RSS feeds 5 add_filter('the_generator', '__return_empty_string'); 6
7 // Remove version from scripts and styles 8 function remove_version_scripts_styles($src) { 9 if (strpos($src, 'ver=')) { 10 $src = remove_query_arg('ver', $src); 11 } 12 return $src; 13 } 14 add_filter('style_loader_src', 'remove_version_scripts_styles', 9999); 15 add_filter('script_loader_src', 'remove_version_scripts_styles', 9999);
Remove WordPress Version Number
This snippet removes the WordPress version number from various locations in your site, which is a basic security hardening practice. Hiding your WordPress version makes it harder for attackers to target known vulnerabilities in specific versions.
// Remove version from head
remove_action('wp_head', 'wp_generator');
// Remove version from RSS feeds
add_filter('the_generator', '__return_empty_string');
// Remove version from scripts and styles
function remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'remove_version_scripts_styles', 9999);
Why This Matters
Security Through Obscurity: While not a complete security solution, hiding your WordPress version removes one piece of information that attackers can use to target your site.
Professional Appearance: Removing version strings from source code looks more professional and prevents clients or competitors from easily identifying your CMS.
Where to Add This Code
- functions.php: Add to your child theme's functions.php file
- Custom Plugin: Better practice - create a mu-plugin in
/wp-content/mu-plugins/ - Site Plugin: Include in your custom site functionality plugin
Related Snippets
Add Custom Admin Column
Add custom columns to the WordPress admin posts list with sortable functionality
// Add the custom column header
function add_featured_image_column($columns) {
// Insert after title column
$new_columns = array();
...Disable Gutenberg Block Editor
Disable the Gutenberg editor and use the Classic Editor instead
// Method 1: Disable Gutenberg completely
add_filter('use_block_editor_for_post', '__return_false', 10);
// Method 2: Disable for specific post types only
...Register Custom Post Type
Complete example of registering a custom post type with all common options
function register_portfolio_post_type() {
$labels = array(
'name' => _x('Portfolio Items', 'Post type general name', 'textdomain'),
'singular_name' => _x('Portfolio Item', 'Post type singular name', 'textdomain'),
...