DEV Community

Cover image for Remove version strings from CSS and JS link hrefs in WordPress
Chris Texe
Chris Texe

Posted on

Remove version strings from CSS and JS link hrefs in WordPress

Yesterday I gave you a quick tip how to remove meta generator tag in WordPress. After applying this tip you can still see the WordPress version in the source code:

WordPress version in link hrefs

What to do if you want to hide it? Just apply below code into functions.php file of your theme.

If you want more tips follow me on Twitter: @TexeChris:

Top comments (1)

Collapse
 
moopet profile image
Ben Sinclair

This is probably there to ensure people don't hang on to outdated versions in their caches. You can set expires and so on but cache invalidation is still one of the hard problems and it doesn't always work how you want. If they added this to Wordpress, it's probably because there were issues raised with it not working.

You can get the same effect but without giving away version information by doing what you're doing but then adding another query string item like ?cachebust=86452542 where that number is linked to the version number in a non-reversible way like this (untested, I don't have Wordpress):

$src = remove_query_arg('ver', $src);
$src = add_query_arg('cachebust', md5($wp_version . "salt here"), $src);
Enter fullscreen mode Exit fullscreen mode