Uncaught TypeError: $ (& hellip;). The accordion is not a function in wordpress

advertisements

Hello I am using the jQuery UI accordion on a website with wordpress and I get the error: "Uncaught TypeError: $(...).accordion is not a function"

In my functions.php I load a app.js, where I have bundled the jQuery UI file and other jQuery plugins, with this function: wp_enqueue_script( 'theme-js', get_template_directory_uri() . '/js/app.js', array('jquery'), null, true );

To bundle the app.js file I use webpack.

This is how i include jQuery UI in my main.js in webpack:

var $ = window.jQuery;
var jqueryUi = require("./jquery-ui.min.js");

I already disabled all plugins on my wordpress installation and deleted othe jQuery plugins.

Thank you.


1- Default Scripts Included and Registered by WordPress
2- You did not add/call/enqueue jQuery UI accordion
wp_enqueue_script('jquery-ui-accordion');
You will maybe need to add/call/enqueue jQuery UI Core wp_enqueue_script('jquery-ui-core');
This is because .accordion()is a jQuery UI effect and not just jQuery !
3- Be sure to wrap your JS with ;
jQuery( document ).ready( function( $ ) { PUT YOU JS HERE });
Final note : are you using node.js ?
If not, what is this require ???
Hope this helps, SYA