Skip to content

Instantly share code, notes, and snippets.

@maddisondesigns
Last active April 6, 2019 19:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maddisondesigns/c039d9460a78096713c9 to your computer and use it in GitHub Desktop.
Save maddisondesigns/c039d9460a78096713c9 to your computer and use it in GitHub Desktop.
Close all the Divi accordions on page load. Works with Divi 2.5 and above
/**
* Toggle the class on the accordion so that they're all closesd on page load
*/
jQuery( document ).ready( function( $ ) {
$(function() {
$(".et_pb_accordion .et_pb_toggle_open").addClass("et_pb_toggle_close").removeClass("et_pb_toggle_open");
$(".et_pb_accordion .et_pb_toggle").click(function() {
$this = $(this);
setTimeout(function() {
$this.parent().removeClass("et_pb_accordion_toggling");
}, 700);
});
});
} );
/**
* Enqueue our theme scripts & styles
*/
function child_scripts_styles() {
// Enqueue our common scripts
wp_register_script( 'commonjs', trailingslashit( get_stylesheet_directory_uri() ) . 'js/common.js', array( 'jquery', 'divi-custom-script' ), '1.0', true );
wp_enqueue_script( 'commonjs' );
}
add_action( 'wp_enqueue_scripts', 'child_scripts_styles' );
@ChAsadUrRehman
Copy link

instead of creating a separate JS file and then enqueuing it using functions.php file we can paste that code in DIVI Theme options or in a code module.
Using the code module is the best approach as it will load the JQuery code on the only required page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment