Posts Tagged ‘ jquery

WordPress and jQuery UI

While working on a quite large WordPress plugin, I’ve started to use jQuery UI for all sorts of widgets on the admin panels. At first I was delighted that that WordPress (3.0.1) had the UI libraries pre-packaged, thinking that it would save me the trouble of including them myself. Well, turns out that was wishful thinking!

For some reason the WordPress version of jQuery UI is severely stripped down. Out of the box, I couldn’t use Dialog, Datepicker and Accordion elements. I couldn’t find a CSS file for it, either. First, I worked around this by downloading the official jQuery UI distro and selectively including the missing elements. What I should have done much sooner is simply ditch the packaged version and use the official one!

To get it to work:

  • download jQuery UI 1.7.3, with all components selected
  • in the admin_init action callback, register┬áthe script and stylesheet
  • in the admin_menu callback, enqueue the library, with the packaged jQuery as a dependency:
    wp_enqueue_script( ‘my-jquery-ui’, null, array(‘jquery’), null, true );

That way you don’t even have to explicitly enqueue the base jQuery library, and I haven’t hit a snag since.