Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 35 down vote accepted

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().

share|improve this answer
    
wow. haven't ever seen this before.. +1 –  kaiser Mar 9 '11 at 14:39
2  
@kaiser Yeah, it didn't even have docs on the Codex until I added them this morning. –  Annika Backstrom Mar 9 '11 at 20:36
    
i also started adding stuff to the codex. Just added has_nav_menu() to conditional tags (also new for me) and a whole load of stuff to the function reference. The reference is extremly incomplete and i really wonder why so less people add stuff there... –  kaiser Mar 9 '11 at 22:45
    
Thanks for adding this to the codex, too! –  Taylor Dewey Nov 4 '11 at 17:05
    
This is amazing! Thanks for adding it to the codex. –  CookiesForDevo Apr 19 '12 at 15: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.

share|improve this answer
    
My Hero! Thanks a lot! +1 –  kaiser Mar 3 '11 at 20:32
1  
Down voted this due lack of sanity checking, leaves the possibility for fatal errors. –  Backie Mar 4 '11 at 8:49
1  
@Backie, but you understand that this is a proof of concept? –  toscho Mar 4 '11 at 11:59
    
wp_script_is() is a better and safer solution (Adam Backstrom` ) solution –  chrisjlee Aug 4 '11 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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