Can values entered in a plugin’s admin be used in the URLs of enqueued scripts?

  javascript, plugins, variables, wordpress

In my plugin I’m enqueueing a script like so:

wp_enqueue_script( ‘myscript_js’, ‘https://example.com/v0.0.14/myscript.min.js’, array(‘jquery’),null,true );

In the admin page of the plugin I’d like the user to be able to enter the version of the script that they are using. It’s hard-coded at 0.0.14 now. Is there a way to pull that info from the plugin admin and use it as a variable in wp_enqueue_script?

So I might end up with something like:

var version = $value_from_plugin_admin;
wp_enqueue_script( ‘myscript_js’, ‘https://example.com/’. version . ‘/myscript.min.js’, array(‘jquery’),null,true );

Source: Ask Javascript Questions

LEAVE A COMMENT