Since this question was written, a lot has changed with WordPress. Here is a new way to prevent WordPress from displaying its version number:
// remove version from head
remove_action('wp_head', 'wp_generator');
// remove version from rss
add_filter('the_generator', '__return_empty_string');
// remove version from scripts and styles
function remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'remove_version_scripts_styles', 9999);
No editing required. Add to functions.php and done. Or add via simple custom plugin. The choice is yours! :)
isn't this answer directly copied from here? You should always give credit to original author, unless you wrote that article – VishwaMar 13 '19 at 10:57
Added the link to the original article. No offense. I just wanted to help people solve the problem. I never took the credit for myself. – AmrMar 14 '19 at 18:19
I didn't implied you did, just showed the proper way to do it. that's all :) – VishwaMar 15 '19 at 4:16
1Nice! Unfortunately it doesn't answer OP's question on how to keep it for one certain CSS. – leymannxMay 28 '19 at 20:34
// remove version from scripts and styles
function remove_version_scripts_styles($src) {
if (strpos($src, 'yourfile.js')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('script_loader_src', 'remove_version_scripts_styles', 9999);