WordPress is the most popular content management system in the world. Its popularity also made 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 of your site from the world.
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 the 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 from the world.
In this article, I show you how to remove the WordPress version from CSS and JS, HTML head, and RSS feed. These are the places where WordPress adds its version number.
Where You Can See WordPress Version?
If you want to see a WordPress version then, of course, you will get it from the dashboard. But this topic is about hiding versions from the outside world. On the front end, if you view the source of your web page, you will notice the version number appended to all your custom CSS and JS files. It may seem like
YOUR_SITE_URL/wp-content/themes/twentytwenty/js/custom.js?ver=6.0.3
The WordPress version also displays under the head section of the page.
<meta name="generator" content="WordPress 6.0.2" />
The third place where people can get your version of WordPress is from the 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 styles and scripts. To do so, add the code below to your active theme’s functions.php
file.
// 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.
Note: This code would also remove versions from the plugin’s CSS and JS files. Usually, the plugin’s version number is appended to these files.
Remove Version from WordPress Head and RSS Feed
In order to remove a version from the head section and feed your code will be as follows:
// 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
- How to Build Custom Elementor Widget
- How to Add Code After the Body Tag in WordPress
- Adding Custom Image Button with Media Uploader in WordPress
If you liked this article, then please subscribe to our YouTube Channel for video tutorials.
Buddy many many thanks
How do I change the background on my blogspot including sidebars?
You need to apply some css tricks for it. You can apply background-color property for it.