Action Since 3.0.0 uncanny-toolkit-pro

learndash-course-heading-before

Fires before the course heading. Fires before the LearnDash course title and description are displayed, passing the course and user IDs.

add_action( 'learndash-course-heading-before', $callback, 10, 2 );

Description

Fires before the LearnDash course heading is displayed. This action hook provides access to the current course and user IDs, allowing developers to inject custom content, modify heading elements, or perform actions immediately before the course title and subtitle appear on the single course page.


Usage

add_action( 'learndash-course-heading-before', 'your_function_name', 10, 2 );

Parameters

$course_id (int)
Course ID.
$user_id (int)
User ID.

Examples

add_action( 'learndash-course-heading-before', 'my_learndash_before_course_heading_content', 10, 2 );

/**
 * Adds custom content before the LearnDash course heading.
 *
 * @since 1.0.0
 *
 * @param int $course_id The ID of the current course.
 * @param int $user_id   The ID of the current user.
 */
function my_learndash_before_course_heading_content( $course_id, $user_id ) {
	// Check if the user has completed the course.
	if ( function_exists( 'learndash_is_user_complete' ) && learndash_is_user_complete( $course_id, $user_id ) ) {
		echo '<div class="learndash-course-completed-notice">';
		echo '<p>' . esc_html__( 'Congratulations! You have successfully completed this course.', 'your-text-domain' ) . '</p>';
		echo '</div>';
	}

	// Optionally, display a specific message for enrolled but not completed users.
	if ( ! learndash_is_user_complete( $course_id, $user_id ) && learndash_is_user_enrolled( $course_id, $user_id ) ) {
		$course = get_post( $course_id );
		if ( $course ) {
			echo '<div class="learndash-course-in-progress-notice">';
			echo '<p>' . sprintf( esc_html__( 'You are currently enrolled in %s. Keep up the great work!', 'your-text-domain' ), esc_html( $course->post_title ) ) . '</p>';
			echo '</div>';
		}
	}
}

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-course.php:169

* Fires before the course heading.
				 *
				 * @since 3.0.0
				 *
				 * @param int $course_id Course ID.
				 * @param int $user_id   User ID.
				 */
				do_action( 'learndash-course-heading-before', $course_id, $user_id );
				?>

				<h2>
				<?php
				printf(
					// translators: placeholder: Course.
					esc_html_x( '%s Content', 'placeholder: Course', 'learndash' ),


Scroll to Top