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 ...
To enable Animate.css in WordPress, you need to follow these steps:Download the Animate.css library First, go to the Animate.css website (https://animate.style/) and click on the &#34;Download&#34; button to obtain the CSS file. Upload the Animate.css file Nav...
To hide the thumbnail image in a WordPress post, you can use CSS code in your theme&#39;s style.css file or in the Customizer&#39;s Additional CSS section. Here&#39;s how you can do it:Access your WordPress dashboard.Go to Appearance and select Editor or Custo...