1

Does anyone know how to enqueue the script "Jquery UI Tabs" in admin area? I want to use it inside my theme options page. Already read the related wordpress documentation but with no results... I have added UI Tabs to the front-end and works fine but I cant add it in the admin area... Thanks in advance.

1 Answer 1

4

I normally load it as a dependancy of my plugin's js file like so:

if ( is_admin() ) {
    //load my plugin's js
    add_action('admin_print_scripts', 'my_plugin_load_js' );

}

function my_plugin_load_js() {
    $plugin_js = WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/my-plugin.js';
    wp_enqueue_script('my-plugin-js', $plugin_js, array('jquery-ui-tabs'), '1.0');

}
6
  • kalengi thank you very very much. works fine! Should I use admin_print_scripts or admin_enqueue_scripts?
    – Arg Geo
    Commented Jul 23, 2012 at 22:26
  • Ah, and how could I enqueue UI Tabs without any other custom js file?
    – Arg Geo
    Commented Jul 23, 2012 at 22:29
  • re: admin_print_scripts vs admin_enqueue_scripts - seems there aren't any strict rules on which to use. In my case I just went with the one that worked and stuck with it.
    – KalenGi
    Commented Jul 23, 2012 at 23:00
  • re: enqueue UI Tabs other custom js - You could achieve this by using wp_enqueue_script('jquery-ui-tabs', PATH_TO_JQUERY_UI_TABS_JS, array('jquery'), JQUERY_UI_TABS_VERSION);. I stay away from this aproach due to 1) You have to know the path to the ui-tabs js file. 2) You have to keep track of the ui-tabs version information. I'd much rather leave those tasks to WP.
    – KalenGi
    Commented Jul 23, 2012 at 23:08
  • 1
    You don’t need the is_admin() check. 'admin_print_scripts' will never be fired on the front-end.
    – fuxia
    Commented Jul 24, 2012 at 2:29

Your Answer

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

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