How to Get Data (Code) of Registered JS Script in WordPress?
WordPress has a bunch of registered scripts. Sometimes it's necessary to get the code of such a script and then output this code on the screen. For example, this may be necessary when there is a need to output the script code directly in the body of an HTML document in the <script> tag.
You can get the script code by its identifier (see the ID column in the description of wp_enqueue_script()) using the method WP_Dependencies::query().
Example of outputting the code of the "underscore" script:
echo file_get_contents( ABSPATH . $GLOBALS['wp_scripts']->query('underscore')->src );
Getting Data of Registered Styles
Similarly, you can obtain data of the core styles, including the URL of the style file, its version, etc. To do this, use the variable:
$GLOBALS['wp_styles'];
// example:
$dashicons = $GLOBALS['wp_styles']->query('dashicons');
print_r( $dashicons );
/*
_WP_Dependency Object
(
[handle] => dashicons
[src] => /wp-includes/css/dashicons.min.css
[deps] => Array
(
)
[ver] =>
[args] =>
[extra] => Array
(
)
[textdomain] =>
[translations_path] =>
)
*/