1

Is it possible to get a script url from one of my working scripts, by handle?

So for example if i have a plugin's JS file registered with the handle wp-js-plugin and i want to get this JS file's url. how can i do that?

mondi
  • 529
  • 3
  • 16

2 Answers2

3

For more info dump $wp_scripts

function get_script_src_by_handle($handle) {
    global $wp_scripts;
    if(in_array($handle, $wp_scripts->queue)) {
        return $wp_scripts->registered[$handle]->src;
    }
}
Sky
  • 325
  • 2
  • 12
0

Simple:

const scriptUrls = [...document.querySelectorAll('script')].map(e=>e.src)

This will list all the urls for each script.

mattemyo
  • 99
  • 1
  • 4
  • Maybe i wasn't clear in my question. i'm looking for a way of echoing a specific script url. ("i will give you the scripts handle and you will echo the script's url) – mondi May 26 '19 at 14:45