HomeCoding & Programming

Remove WordPress version number from the head section and RSS feeds & also from version parameter in JS and CSS files

Remove WordPress version number from the head section and RSS feeds & also from version parameter in JS and CSS files
Like Tweet Pin it Share Share Email

Remove WordPress version number from the head section and RSS feeds & also from version parameter in JS and CSS files

 

By default WordPress adds a Meta tag in the headers which displays the current using WordPress version number.

This version number is added just for tracking the site on WordPress, it is not required by your application, but this information can be very much useful to hacker to identify which version of WordPress you are using.

If you are not using latest WordPress version, the hackers can target the known vulnerabilities in that version to hack your site.
You can check all the Vulnerability in “Open Sourced Vulnerability Database” founded at http://osvdb.org/

 

There are various ways that can be used to remove this information below is the best one.

 

Add these following codes to in your functions.php file of your theme according to your requirements.

<?php

/* Function to hide WordPress version number
*  from the head section and RSS feeds on your site.
*/

function my_remove_version_info() {
return ”;
}
add_filter(‘the_generator’, ‘my_remove_version_info’);
?>

 

Remove the “ver” parameter from all enqueued CSS and JS files in the page

<?php

/* remove wp version param from any enqueued scripts (css/js)*/
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, ‘ver=’ ) )
$src = remove_query_arg( ‘ver’, $src );
return $src;
}
add_filter( ‘style_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );
add_filter( ‘script_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );
?>

 

Remove only the “ver” parameters which have WordPress version number from all enqueued CSS and JS files in your page.

<?php

/* remove wp version param from any enqueued scripts (css/js)*/
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, ‘ver=’ . get_bloginfo( ‘version’ ) ) )
$src = remove_query_arg( ‘ver’, $src );
return $src;
}
add_filter( ‘style_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );
add_filter( ‘script_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );
?>

 

It is always recommended that you have the most updated version of WordPress.