jQuery.accordion isn’t a function even when enqueued

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:-

Read More
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?

Related posts

Leave a Reply

1 comment

  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);