How to Remove Version from CSS and JS in WordPress

WordPress is the most popular content management system in the world. It’s popularity also makes it a top target of hackers. There are several recommended ways to prevent your WordPress website from hackers. One of them is to hide the WordPress version you are using from the world.

In this article, I show you how to remove the WordPress version from CSS and JS, HTML head, and RSS feed.

On your WordPress website, WordPress displays its version by default for tracking purposes. This is how we come to know WordPress is the largest used CMS around the world. If you are running an updated version then showing your WordPress version number will not be an issue. But in the case of older versions, hackers might take benefit of security vulnerabilities of that specific version. So it is always recommended to keep your WordPress version updated. And if your site is not using the latest version, then hide the version used from the world.

Where You can See WordPress Version?

If you want to see a version of WordPress then, of course, you will get it from the dashboard. But this topic is about hiding versions from the outside world. On the frontend, if you view the source of your web page then you will notice the version number appended to all your CSS and JS files. It may seem like

YOUR_SITE_URL/wp-content/themes/twentyseventeen/js/custom.js?ver=5.3.2

The WordPress version also displays under the head section of the page.

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

The third-place where people can get your version of WordPress is from feed URL – YOUR_SITE_URL/feed.

For the matter of security, WordPress developers should remove a version from all these 3 sources.

Remove Version from CSS and JS

Let’s start with removing versions from style and scripts. To do so, add the code below in your active theme’s functions.php file.

<?php
// remove wp version number from scripts and styles
function remove_css_js_version( $src ) {
    if( strpos( $src, '?ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'style_loader_src', 'remove_css_js_version', 9999 );
add_filter( 'script_loader_src', 'remove_css_js_version', 9999 );

Now if you view the source of a page your WordPress version number should be removed from all your styles and scripts.

Remove Version from WordPress Head and RSS Feed

In order to remove version from the head section and feed your code will be as follows:

<?php
// remove wp version number from head and rss
function artisansweb_remove_version() {
    return '';
}
add_filter('the_generator', 'artisansweb_remove_version');

That’s it! It is that simple. I hope you understand how to remove the WordPress version from CSS and JS, head, and RSS feed. Let me know your thoughts and suggestions in the comment section below.

Related Articles

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

2 thoughts on “How to Remove Version from CSS and JS in WordPress

Leave a Reply

Your email address will not be published.