Using WordPress 3.4.2, the wp_enqueue_script documentation seems to indicate that jQuery UI libraries can be loaded simply by referencing their handles. I have the following code with no prior wp_register_script():
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
The enqueue for ‘jquery’ works fine, but the enqueue for ‘jquery-ui-core’ isn’t working.
I realize that I can register and load script explicitly using Google CDN (or make explicit references to library elements in WordPress install) … but again documentation makes me think I shouldn’t have to do this w/ WordPress current version.
Anyone know why this doesn’t work?
I guess you have to really read the Codex about wp_enqueue_script()
again and then dig into jQuery a little bit more. jQuery UI is a dependency of jQuery (which means it depends on having jQuery loaded). So you need to load jQuery first, before loading jQuery UI (or jQuery UI Mobile).
Edit as per @ChipBennet and @MannyFleurmond comments below:
- There’s no need to add
array( 'jquery' )
as $dependency
argument for jquery-ui-core
, as Chip shows us in this core reference
- As Manny stated, you need to add every effect/plugin by itself, like for e.g.
'jquery-effects-fold'
, 'jquery-ui-resizable'
or 'jquery-effects-explode'
.
-
The example is right, but missing the (possibly) needed plugins
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core' );