wp_script_is()WP 2.8.0

Check whether a script has been added to the queue.

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

1 time — 0.000026 sec (very fast) | 50000 times — 0.09 sec (speed of light) | PHP 7.0.5, WP 4.5.2

No Hooks.

Return

true|false. Whether the script is queued.

Usage

wp_script_is( $handle, $list );
$handle(string) (required)
Name of the script.
$list(string)
Status of the script to check. Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
Default: 'enqueued'

Examples

0

#1 Connecting the script with verification

This example shows how to connect the script /js/fluidvids.min.js by first checking if this script has already been connected and added to the output queue.

If the script has already been added to the queue, the code will do nothing. If the script has not yet been added, it will be connected and added to the queue for processing:

if ( ! wp_script_is( 'fluid_vids', 'enqueued' ) ) {
	wp_register_script( 'fluid_vids', plugin_dir_url(__FILE__).'js/fluidvids.min.js');
	wp_enqueue_script( 'fluid_vids' );
}

Changelog

Since 2.8.0 Introduced.
Since 3.5.0 'enqueued' added as an alias of the 'queue' list.

Code of wp_script_is() WP 5.9.3

function wp_script_is( $handle, $list = 'enqueued' ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );

	return (bool) wp_scripts()->query( $handle, $list );
}