Want to know what WordPress Theme a site is using? Check Out Now!

How to Hide/Remove WordPress Version Number?

WordPress adds the version of currently installed WordPress in your website’s source code.

This allows hackers to identify the WordPress version and find security vulnerabilities and bugs which ultimately increases the probability of your website getting hacked.

Removing the WordPress version number is one of the security measures practiced to reduce the risk of any breaches.

Here’s how you can remove the WordPress version number the right way.

1. Remove WordPress Version Number Meta Tag

WordPress adds a meta tag to display the version of currently installed WordPress on a website.

<meta name="generator" content="WordPress 5.8.2" />

To remove the above meta tag from your website’s HTML code, you need to add the below code in your functions.php file.

/**
 * Remove WordPress Version Number Meta Tag and from RSS Feeds
 *
 * @return string WordPress version number
 */
function maverick_remove_wordpress_version() {
    return '';
}
add_filter('the_generator', 'maverick_remove_wordpress_version');

Note: You may come across another piece of code that removes the meta tag from the source code. I will not recommend you to use this method because it only removes the meta tag from the source code and not from the RSS feeds.

/**
 * Remove WordPress Version Number From Source Code. 
 */
remove_action('wp_head', 'wp_generator');

2. Remove WordPress Version Number from Script and Style Files

By default, WordPress adds the version number to each enqueued CSS and JS file which allows hackers to identify the WordPress version number.

There are two filter hooks ‘style_loader_src’ and ‘script_loader_src’ used to remove the version number from the asset files.

/**
 * Remove WordPress Version Number from Script and Style Files
 *
 * @param string $src   Source File
 * @return string $src   Source File
 */
function maverick_remove_wp_version_from_files( $src ) {
    if( strpos( $src, '?ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'style_loader_src', 'maverick_remove_wp_version_from_files', 9999 );
add_filter( 'script_loader_src', 'maverick_remove_wp_version_from_files', 9999 );

Leave a Reply

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