views:

68

answers:

2

I created a wordpress plugin (say P1 ) in which I used fancybox (a jquery plugin). I included its js using wordpress's wp_enqueue_script() function.

But, on my client wordpress blog, he is using some other wordpress plugin, one of them (say P2) also use fancybox.

When both these P1 and P2 are active, fancybox js loads 2 time one from P1 and another from P2. And due to this it gives error

loading is undefined (on line 36)

can I

  1. prevent fancybox to load 2 or more times from my wordpress plugin
  2. or handle this js error

prevent

A: 

you can prevent loading your script twice from your side (wordpress side) if you have control over it.

You can probably use the typeOf operator to see if a particular fancybox has already loaded and if yes you do not include it twice.

sushil bharwani
A: 

wp_enqueue_script is your friend! Providing the other plugin is using the correct technique for loading JavaScript, you can simply queue the same handle in your plugin.

That way, Fancybox will only ever load once, regardless if both plugins are queueing it.

TheDeadMedic