Action Since 3.0 uncanny-toolkit-pro

learndash-lesson-content-list-after

Action to add custom content before the course certificate link Fires after the lesson content list is displayed, allowing custom content insertion before the certificate link.

add_action( 'learndash-lesson-content-list-after', $callback, 10, 1 );

Description

Fires after the lesson content list is displayed and before the course certificate link. Developers can use this hook to add custom content or logic after the lesson content, utilizing the current lesson, course, and user IDs.


Usage

add_action( 'learndash-lesson-content-list-after', 'your_function_name', 10, 1 );

Parameters

$course_id (mixed)
- **$user_id** `mixed`

Examples

/**
 * Adds custom content after the lesson content list.
 *
 * This example displays a list of related lessons if the current lesson
 * has any assigned via a custom meta field.
 *
 * @param int $lesson_id The ID of the current lesson.
 * @param int $course_id The ID of the current course.
 * @param int $user_id   The ID of the current user.
 */
function my_learndash_lesson_content_list_after_handler( $lesson_id, $course_id, $user_id ) {
	// Check if there are any related lessons assigned to this lesson.
	$related_lesson_ids = get_post_meta( $lesson_id, 'related_lessons', true );

	if ( ! empty( $related_lesson_ids ) && is_array( $related_lesson_ids ) ) {
		echo '<div class="learndash-lesson-related-lessons">';
		echo '<h3>Related Lessons:</h3>';
		echo '<ul>';

		foreach ( $related_lesson_ids as $related_lesson_id ) {
			// Ensure the related lesson is a valid lesson post.
			if ( get_post_type( $related_lesson_id ) === 'sfwd-lessons' ) {
				$lesson_title = get_the_title( $related_lesson_id );
				$lesson_link  = get_permalink( $related_lesson_id );
				echo '<li><a href="' . esc_url( $lesson_link ) . '">' . esc_html( $lesson_title ) . '</a></li>';
			}
		}

		echo '</ul>';
		echo '</div>';
	}
}
add_action( 'learndash-lesson-content-list-after', 'my_learndash_lesson_content_list_after_handler', 10, 3 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/templates/single-ld30-lesson.php:225

<?php
			endif;
			/**
			 * Action to add custom content before the course certificate link
			 *
			 * @since 3.0
			 */
			do_action( 'learndash-lesson-content-list-after', get_the_ID(), $course_id, $user_id );

		endif;

	endif; // end $show_content

	/**
	 * Set a variable to switch the next button to complete button


Scroll to Top