Browse: Home / Snippets /

Collapse course navigation widget list items

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

add_action( 'wp_footer', function () {
	?>
	<script>
	jQuery( document ).ready(function() {
		if ( jQuery('#course_navigation').length ) {

			// Get any exanded list items. 
			jQuery('#course_navigation div.learndash_navigation_lesson_topics_list div.list_arrow.expand').each( function(){
				var list_id = jQuery(this).parent().attr('id');

				// list_id will look something like 'lesson_list-xxx'
				// We need to split off the xxx lesson ID on the end. 
				if ( typeof list_id !== 'undefined' ) {
					var list_item_sub = list_id.substr(0, 12);
					if ( list_item_sub == 'lesson_list-' ) {
						var list_item_id = list_id.replace( 'lesson_list-', '' );
						
						// finally call the flip_expand_collapse() function to collapse the list
						flip_expand_collapse("#lesson_list", list_item_id);
					}
				}
			})
		}
	});
	</script>
	<?php
});