Remove WordPress Version Number
Home » WordPress » How to Remove WordPress Version Number

How to Remove WordPress Version Number

How to Remove WordPress Version Number – Removing the WordPress version number from your site can enhance security by obscuring which version of WordPress you’re running, thus shielding information that could be used by attackers to exploit specific vulnerabilities associated with particular versions.

How to Remove WordPress Version Number

Here’s how to remove the WordPress version number using a custom function in your theme’s functions.php file or using any code snippet plugins:

Step 1: Access Your Theme’s functions.php

First, access your WordPress theme’s functions.php file. You can do this either by:

  • Accessing it directly via an FTP client or through the file manager in your hosting control panel.
  • Navigating to Appearance > Theme Editor in your WordPress dashboard and selecting functions.php from the list on the right.

Step 2: Add the Custom Code

Once you’re in the functions.php file, add the following custom code snippet at the end of the file. This code will remove the WordPress version number from both the head of your HTML documents and the feeds.

function zerobytecode_remove_wp_version_strings($src) {
    global $wp_version;
    parse_str(parse_url($src, PHP_URL_QUERY), $query);
    if (!empty($query['ver']) && $query['ver'] === $wp_version) {
        $src = remove_query_arg('ver', $src);
    }
    return $src;
}
add_filter('script_loader_src', 'zerobytecode_remove_wp_version_strings');
add_filter('style_loader_src', 'zerobytecode_remove_wp_version_strings');

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

Or you can simply use the following code snippet:

add_filter('the_generator', '__return_empty_string');

Explanation of the Code

  • zerobytecode_remove_wp_version_strings: This function targets URLs of enqueued scripts and styles that include the WordPress version number as a query string. It removes this version number from the query string, ensuring that the version number isn’t easily displayed in the page source.
  • zerobytecode_remove_wp_version: This function removes the WordPress version number from RSS feeds by filtering the generator tag, which by default outputs the WordPress version.

Step 3: Save and Test

After adding the code, save the changes to your functions.php file. Then, test your site:

  • Load your website and view the page source (Ctrl+U on most browsers).
  • Check the HTML head section and RSS feed to ensure that the WordPress version number is no longer present.

By implementing this code, you effectively obscure your site’s WordPress version, helping to shield it against targeted attacks.

Also read: How to Allow SVG Files Upload on WordPress

Always remember to back up your functions.php file before making changes to avoid issues if errors occur. If you need any further customization or have another question, feel free to ask!

Similar Posts