1

I'm trying to implement a jQuery accordion for a client of ours. Basically, it's this tutorial (http://wp.tutsplus.com/tutorials/creative-coding/create-an-faq-accordion-for-wordpress-with-jquery-ui/) but having problems enqueuing the jQuery.

Basically, this is the code that is trying to enqueue the accordion script from the tutorial:-

add_action( 'wp_enqueue_scripts', 'fl_enqueue' );

function fl_enqueue() {
        wp_register_style('fl-jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/south-street/jquery-ui.css');
        wp_enqueue_style('fl-jquery-ui-style');
        wp_register_script('fl-custom-js', get_template_directory_uri() . '/faq/faq.js', 'jquery-ui-accordion', '', true);
        wp_enqueue_script('fl-custom-js');
}

When loading the page with Firebug, I'm getting the error TypeError: jQuery(...).accordion is not a function. I also cannot seem to see the accordion script being enqueued. However, the faq.js IS being loaded (which I think is odd, as it's a dependancy of the accordion script).

Baffled by this, any ideas?

1

The 3rd parameter in the call to wp_register_script() should be an array of dependencies - not a string.

Change this:

wp_register_script('fl-custom-js', get_template_directory_uri() . '/faq/faq.js', 'jquery-ui-accordion', '', true);

To:

wp_register_script('fl-custom-js', get_template_directory_uri() . '/faq/faq.js', array('jquery-ui-accordion'), '', true);

  • Cheers that worked :) - loading the script but the accordion isn't working. Should be easy to figure out why though..... – Rhys Wynne Feb 8 '13 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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