Check the Version of an Enqueue’d External Library

I can’t find a nice way of doing it though wp_script_*, but you can go to the global directly:

global $wp_scripts;
$version = $wp_scripts->query( 'jquery' )->ver;

Here the query returns the script’s _WP_Dependency object, and then we can get the version from it. (Annoyingly wp_script_is( ..., 'registered' ) fetches the _WP_Dependency but then casts the result to a bool to return.)

This only works for registered scripts; apologies I don’t know the distinction, but AFAICS a script can only be queued if it’s registered, and it’s only the registered data that holds the version.

Leave a Comment