Remove version from WordPress enqueued CSS and JS

2 minutes read

WordPress functions wp_enqueue_script / wp_register_script and wp_enqueue_style / wp_register_style add additional version info in the end of the JavaScript and CSS files you link (include or add) using these functions. This version info is important to ensure that the correct version of the file is sent to the browser regardless of caching.

Below screenshot explains how a version number appears in WordPress enqueued scripts and styles, see the highlighted part:

Version info shown by WordPress enqueue functions

Preventing WordPress to add version number to scripts and styles

Sometimes the version number in our scripts turns out to be unnecessary in WordPress theming and plugin projects. This article shows how to prevent WordPress adding a version number to your scripts and styles easily without adding any additional PHP functions to your theme or plugins.

Note: For DIY trials, these functions are generally used in functions.php file of your theme to link the CSS & JS files.

Take a look at the format of wp_enqueue_script function below:

<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>

The functions wp_register_script, wp_enqueue_style and wp_register_style also carry the same parameters. The parameter $ver is responsible to show the version of your script or style.

If you have to specify a version to your script or style, just put the version number in single quotes in the $ver parameter. If you don’t want to specify a version, you may set it to false, but then a version number equal to the current version of WordPress will be added automatically as the version of your script or style.

In order to prevent your enqueued scripts and style in WordPress to use a version number, all you need to do is use null value in the $ver parameter. Given below is how you’ll implement it in the WordPress enqueue functions:

<?php wp_register_script('basic', plugins_url('js/basic.js', __FILE__), array(), null, true); >

Similarly, you should add the null value to the version parameter in wp_register_script, wp_enqueue_style and wp_register_style functions also. That’s it!

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

Gutenberg has brought in things which look quite interesting to enhance our editing task to another level. But I’m sure there are folks like me who don’t like adding one more external CSS file to their theme–the point here is to avoid another render block. If ...
We want to customize lots of things in our WordPress themes, and WordPress gallery style can be one important of those. At first, it may seem easy stuff, but actually it isn’t that easy. As a developer, you may think of customizing the look of WordPress galler...
WordPress automatically adds its current Version number to the head section of the themes. If you view the source of a WordPress-based website, you may find out the WordPress version it is using. Below given is the meta tag that carries that version informatio...