Wordpress - Prevent Version URL Parameter (?ver=X.X.X) on Enqueued Styles & Scripts

Default wp_enqueue_[style/script]() behavior

The default value for the $version argument of wp_enqueue_style() is false. However, that default just means that the stylesheets are given the WordPress version instead.

Solution

Thanks to "Remove version from WordPress enqueued CSS and JS", I learned the undocumented fact that passing in null as a version will remove the version altogether!

Example

wp_enqueue_style( 'wpse-styles', get_template_directory_uri() . '/style.css', array(), null );

Caveat Reminder

It's worth pointing out, as noted in the question, that this should probably only be done during development (as in the specific usecase). The version parameter helps with caching (and not caching) for site visitors and so probably should be left alone in 99% of cases.


Thank you for your post, mrwweb.

I found another solution to this, by creating a very simple plugin you can deactive when the site is no longer under development.

<?php

/*
Plugin name: Strip WP Version in Stylesheets/Scripts
*/

function switch_stylesheet_src( $src, $handle ) {

        $src = remove_query_arg( 'ver', $src );
        return $src;
}
add_filter( 'style_loader_src', 'switch_stylesheet_src', 10, 2 );

?>

I spent a couple minutes trying to find this solution. Thought I might share another option here instead of creating a new Question/Answer.