views:

90

answers:

3

On my site, I load jQuery UI script using the following code:

wp_enqueue_script('nf-jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js')

In my plugin I use the following code:

wp_enqueue_script('wp_filebrowser-jqueryui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js')

The result is that both these lines are added to my header - and loading a script twice is not very good.

Yes, I know I can remove it from either my plugin or my site. But the point is that anyone can download my plugin, and they might already be loading the jQuery UI script.

How can I avoid having a script being added twice?

+2  A: 

This post on Stack Overflow may be helpful on how to test if jQuery UI has been loaded -

Will S
Brilliant. Will check this. Thanks!
Steven
That's related to checking inside the browser, I presume he wants to check via PHP.
Marko
He didn’t tell us, so one can only guess …
Kissaki
@Marko - yes, this would be server side and not done by javascripts. So Wills link is not entierly correct for the answer I'm after.
Steven
+1  A: 

You could deregister the first script by putting this line in your plugin...

wp_deregister_script( 'nf-jquery-ui');

before you call your enqueue_script...

wp_enqueue_script('wp_filebrowser-jqueryui',...

This should remove the first jQuery call on all pages that use your plugin.

awats
Yes, I think `wp_deregister_script`is pretty close to what I need to do.
Steven
A: 

The WP API states the first param is a handler. That one is probably used so a script is only inserted once (although I can not say for sure).

It also defines handlers for jQuery and jQuery UI which you should probably use. Those handlers are for included scripts and jQuery as well as jQuery-ui is listed there. If you want to update consider passing the version to the wp_-function or just replacing the jQuery script file that’s already in use / packaged with wp.

Kissaki