Determine the status of a script - WordPress

Published on Apr 9, 2015 & tagged in WordPress

When making new plugin or customizing WordPress themes in deep, we want to check that if a script has been registered, enqueued, printed, or is waiting to be printed.

This method is very useful to avoid conflicts between scripts during registering/enqueing scripts in our plugins and themes.

The WordPress have a default function to check the status of script.

wp_script_is( $handle, $list );


Default value: None

Default: enqueued

Return Values

True or false.

Example 1

$handle = 'fluidVids.js';
$list = 'enqueued';
if (wp_script_is( $handle, $list )) {
} else {
	wp_register_script( 'fluidVids.js', plugin_dir_url(__FILE__).'js/fluidvids.min.js');
	wp_enqueue_script( 'fluidVids.js' );

Example 2

On the below example, we are going to check that if jQuery is printed & if so, we will add a custom jQuery snippet to our footer from our theme’s functions.php.

function myscript() {
	if( wp_script_is( 'jquery', 'done' ) ) {
	<script type="text/javascript">
	  // script dependent on jQuery
add_action( 'wp_footer', 'myscript' );

Do you need any help on WordPress?

I'm happy to help you. Just fill the form on contact page & I will get back to you within few hours.

Recent Posts

  1. Get current store details - Magento 1.9
  2. Simple ways to improve page conversion on product page
  3. Encrypt Email Addresses - PHP
  4. The add_image_size() function - WordPress best practices
  5. Remove page title using filter - WordPress