Duplicate script in my plugin
-
Hello,
I created a plugin for a client that creates an image gallery shortcode. The shortcode uses a few resources that are already enqueued by another plugin. I don’t want to remove my code and assume that the resource will be there because the client could disable the other plugin and then mine would break. So I Googled around and found “wp_script_is” which seems perfect. The codex even says:
Determine if a script has been registered, enqueued, printed, or is waiting to be printed. Very useful when registering/enqueing scripts in plugins to avoid conflicts with other plugin scripts.
There are four possible values listed for
$handle
:registered
,enqueued
,to_do
anddone
. I have tried them all using a copy/paste from the codex.$handle = 'jquery.swipebox.min.js'; //$list = 'registered'; $list = 'enqueued'; // $list = 'to_do'; // $list = 'done'; if (wp_script_is( $handle, $list )) { return; } else { wp_enqueue_script( 'se2-swipebox-js', $path_to_plugin_folder . 'js/jquery.swipebox.min.js', array( 'jquery' ), '1.0.0', true ); }
Regardless of which value I use for handle, the script is printed. I have tried to adjust the priority of my
add_action
call but that didn’t help either. Anyone see what I’m not doing right here?Thanks,
Swani
- The topic ‘Duplicate script in my plugin’ is closed to new replies.