33

Is it possible to test whether a script or a style was registered using wp_register_script/_style or wp_enqueue_script/_style? All functions doesn't return a value and I'm completely clueless.

I need it to switch between different functions depending on stylesheet-libraries and scripts I offer.

Thank you!

2 Answers 2

53

There is a function called wp_script_is( $handle, $list ). $list can be one of:

  • 'registered' -- was registered through wp_register_script()
  • 'queue' -- was enqueued through wp_enqueue_script()
  • 'done' -- has been printed
  • 'to_do' -- will be printed

Ditto all that for wp_style_is().

0
11

Check $GLOBALS['wp_scripts']->registered for scripts.

Example

function is_enqueued_script( $script )
{
    return isset( $GLOBALS['wp_scripts']->registered[ $script ] );
}

print (int) is_enqueued_script( 'l10n' );

$GLOBALS['wp_styles']->registered works the same way.

3
  • 1
    Down voted this due lack of sanity checking, leaves the possibility for fatal errors.
    – Backie
    Mar 4, 2011 at 8:49
  • 2
    @Backie, but you understand that this is a proof of concept?
    – fuxia
    Mar 4, 2011 at 11:59
  • wp_script_is() is a better and safer solution (Adam Backstrom` ) solution
    – chrisjlee
    Aug 4, 2011 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.