How to remove WordPress version number?Hide version number in WordPress code

By default, when you build a website using WordPress , WordPress leaves a version number mark on your website.

For certain reasons, exposing the WordPress version number could be a security vulnerability for your website if you are using an older version of the software .

How to hide version number hints inside WordPress code?

Now Chen Weiliang will tell you how to hide the WordPress version number.

This is the code that WordPress automatically generates to announce to the outside world which version of WordPress you are using.

Open your WordPress site, right-click on an empty area and select View Source, usually you will find a line of code like this:

<meta name="generator" content="WordPress 5.8.1" />
  • This is the version number of WordPress.
  • In some cases, this tag can also be a security hole for the website.

How to remove WordPress version number?Hide version number in WordPress code

So, in this case, you should hide the WordPress version number your website uses.

There are four places in your WordPress site where you can easily expose your WordPress version number:

  1. In the meta tag in the header of the website source code:
  2. In script and stylesheet files:
  3. In the website RSS feed:
  4. In the readme.html file in the root directory of the website.

Assuming your website always uses the latest version of WordPress, you basically don't have to worry about security issues due to leaking version numbers.

There are many tricks to hiding WordPress version numbers on the web, along with the most complete and concise code.

How to remove version numbers in WordPress code?

In the template's functions.php file, add the following code to remove the WordPress version number:

/* 在 js 文件和 css 文件中隐藏 WordPress 版本号
* @return {string} $src
* @filter script_loader_src
* @filter style_loader_src
*/
function cwl_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', 'cwl_remove_wp_version_strings' );
add_filter( 'style_loader_src', 'cwl_remove_wp_version_strings' );

/* 在 generator meta 标签中隐藏 WordPress版本号 */
function cwl_remove_version() {
return '';
}
add_filter('the_generator', 'cwl_remove_version');
  • This code removes the WP version number included in the first three places.
  • For the readme.html file mentioned in point 4 above, it is located in the root directory of WordPress and you can backup or delete it directly.
mv readme.html readme.bak.html
  • This document is a brief introduction and installation instructions about WordPress.

Of course, the above method hides the version number of WordPress and cannot completely and effectively solve the security holes in the website.

  • The first element of keeping your website secure is keeping your WordPress core software, themes and plugins up to date;
  • use a reliable username and password;
  • Do not use pirated themes and plugins from unknown sources.

We recommend using the Wordfence Security plugin to scan your website for malicious code.

Comment

Your email address will not be published. Required fields are marked with * .

Scroll to Top