wp_script_is()
Determines whether the script file has been registered / added to the output queue / output to the screen.
The function may be useful when writing a plugin, when you need to check whether the specified action has been performed on the specified script. It will help avoid conflicts with loading the same scripts in different plugins.
wp_style_is() — The same check for the style file.
No Hooks.
Returns
true|false. true/false, depending on whether the condition is met or not.
Usage
wp_script_is( $handle, $list );
- $handle(string) (required)
- The identifier (name) of the script being checked. In lowercase.
- $list(string)
The type of check to perform. The following values are allowed:
registeredorscripts— the script has been registered via the wp_register_script() function;enqueuedorqueue— the script has been added to the output queue;doneorprinted— the script has already been processed (has been output to the screen);to_doorto_print— the script has not yet been processed (awaiting output to the screen).
Default: 'enqueued'
Examples
#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. |
wp_script_is() wp script is code WP 6.9
function wp_script_is( $handle, $status = 'enqueued' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
return (bool) wp_scripts()->query( $handle, $status );
}