Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Course Hierarchy Shortcode

Display all lessons, etc., associated with a course in a tree format

// Add Shortcode
function vivi_course_hierarchy( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'id' => '',
		),
		$atts,
		'course-hierarchy'
	);

		// learndash_get_course_lessons_list( int|WP_Post|null $course = null,  int|null $user_id = null,  array $lessons_args = array() )
	    $user_id = get_current_user_id();
	    $courses = learndash_user_get_enrolled_courses( $user_id, array(), true );
	    $lessons = learndash_get_course_lessons_list( $atts['id'],  $user_id, array(), true );
	    $output = '<ul>';
	    foreach ($lessons as $lesson):
	        $postImage = get_the_post_thumbnail($lesson['post']->ID);
	        $postTitle = $lesson['post']->post_title;
	        $postLink = get_post_permalink($lesson['post']->ID);
	        $output .= '<li>' . $postTitle . '</li>';
	    endforeach;
	    $output .= '</ul>';
		return $output;

}
add_shortcode( 'course-hierarchy', 'vivi_course_hierarchy' );