WordPress.org

Ready to get started?Download WordPress

Forums

Loading built in jQuery UI in a plugin (6 posts)

  1. dixie17
    Member
    Posted 3 years ago #

    I am having a stab at writing my first plugin and have encountered a problem including the built in jQuery UI scripts. The code I have is as follows:

    function bda_faqs_load_js() {
    	wp_enqueue_script('jquery');
    	wp_enqueue_script('jquery-ui-core');
    	wp_enqueue_script('jquery-ui-widget');
    }
    
    add_action( 'init', 'bda_faqs_load_js' );

    This doesn't load the required scripts is there something I am missing?

    I would really like to utilise the built in scripts and not load my own version.

  2. s_ha_dum
    Member
    Posted 3 years ago #

    Where do you have this code?

  3. dixie17
    Member
    Posted 3 years ago #

    in a plugin file called bda_faqs.php

  4. s_ha_dum
    Member
    Posted 3 years ago #

    Are you sure that the code is firing? And how do youknow that the scripts aren't loading?

  5. dixie17
    Member
    Posted 3 years ago #

    I inserted an echo statement into the function bda_faqs_load_js which was outputted in the head of the the HTML.

    I know it is not working as when I review the HTML source the required ui.core.js and ui.widget.js are not included on the page.

    If I explicitly declare a javascript with wp_enqueue_script it works e.g.

    function bda_faqs_load_js() {
      wp_enqueue_script('jquery');
      wp_enqueue_script( 'bda-faqs-jquery-ui', plugins_url().'/bda-faqs/bda_faqs.jquery-ui.js', array('jquery'));
    }

    But I really wanted to use the built in versions to keep the plugin as light weight as possible.

  6. s_ha_dum
    Member
    Posted 3 years ago #

    I'm loading jQuery (not the others) with wp_enqueue_script on the 'get_header' hook and it is working fine. Its not what the docs say, but maybe try that instead of 'init'.

Topic Closed

This topic has been closed to new replies.

About this Topic