How to Remove the WordPress Version Number

WordPress leaving it's a footprint on your site for track your site. By default wordpress add meta tag which displays the wordpress version number. Sothis information is very useful for hackers to identify a wordpress version for your running wordpress website. If your wordpress version is old than hacker will try to hack your website.

Many developers display WordPress version in their source code but having information publicly it's not good because it's easy for a hacker to track your site.

It's good things to remove the WordPress version from all part of your website. The WordPress version number appears in three areas on your site.

  • The generator meta tag in the header

<pre>

<meta name="generator" content="WordPress 7.0" /> </pre>

  • Query strings on scripts and styles

<pre>

subscriptions.css?ver=7.0

</pre>

  • In the RSS Feed

<pre>

<generator>http://wordpress.org/?v=7.0</generator>

</pre>

 

This post show you how to remove wordpress version number information.

1) A good way to remove the wordpress version

Add the following code in your theme’s functions.php file of your active child theme (or theme) and save the file. It will remove wordpress version number form both head section and RSS feeds of your site.

<pre>
function my_remove_version_info() {

     return '';

}

add_filter('the_generator', 'my_remove_version_info');

</pre>

 

2)  Right way to remove the wordpress version
Add the following code in your theme’s functions.php file of your active child theme (or theme) and save the file.

<pre>
   remove_action('wp_head','wp_generator');

</pre>

 

3) Remove the wordpress version strings from scripts and styles

Add following code in your theme’s functions.php file of your active child theme (or theme) and save the file.

<pre>
/*

* @return {string} $src

* @filter script_loader_src

* @filter style_loader_src

*/

function 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’, ‘Remove_wp_version_strings’ );

add_filter(‘style_loader_src’, ‘Remove_wp_version_strings’);
</pre>

 

4) Remove the wordpress version  from rss

Add below line of code in your theme’s functions.php file of your active childtheme (or theme) and save the file.

<pre>
add_filter('the_generator', '__return_empty_string');
</pre>

 

5) Remove the wordpress version by wordpress core.

   Edit the /wp-includes/defaults-filter.php file and replace

<pre>add_action('wp_head', 'wp_generator')</pre>

with

<pre>remove_action('wp_head','wp_generator');</pre>

note: You should not do this, as when you upgrade WordPress you might no longer have this hack present.

 

6) Remove wp_head

By default,WordPress executes the wp_generator() function whenever the wp_head() hook is called. Typically, this hook is located in your theme’s header.php file with in the <head> section of the document markup. Removing this hook from your header.php file might break other functions/plugins on your site which rely on this hook. So you should not do this way.

This post mentioned all the way to remove the wordpress version and improving security on your site. We still recommend that you update to the latest version of WordPress because that is the only guaranteed way to keep your site secure.

If you have any query than comment below or contact us. We are happy to help you.