, , , ,

Check whether jQuery library has been loadedIt is a very common issue that just after activating a plugin the whole site broken and from the browser bug tracker we are understanding that the issue reason is related to JS. Actually in most of the cases plugin author are forget to check if jQuery library has been already loaded by the activated theme or by the activated plugins so they override it or duplicate the copy of the library itself. Fortunately, WordPress providing us a function to check this. The function is: wp_script_is(), it uses to make sure that only a copy of jQuery library is currently running.

The before said function returns a Boolean value which determines whether a script has been registered, queued, printed, or is waiting to be printed. You need to pass the handler name of the library you want to test as the first argument of the function:


if( wp_script_is( 'jquery' ) ) {
// do nothing
} else {
wp_enqueue_script( 'jquery' );

Can we do test for other script file using the same function?
Yes, we can do test for any script file with the same function.

Reference link: http://codex.wordpress.org/Function_Reference/wp_script_is