LearnDash: "Resume Course" Button Shortcode
Adds a [wpide_ld_resume course_id="123"] shortcode that takes students straight to the first lesson or topic they have not finished yet.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
add_shortcode( 'wpide_ld_resume', function ( $atts ) {
$atts = shortcode_atts( array( 'course_id' => 0, 'label' => 'Resume course' ), $atts, 'wpide_ld_resume' );
$user_id = get_current_user_id();
$course_id = $atts['course_id'] ? absint( $atts['course_id'] ) : (int) learndash_get_course_id( get_the_ID() );
if ( ! $user_id || ! $course_id || ! sfwd_lms_has_access( $course_id, $user_id ) ) {
return '';
}
$url = get_permalink( $course_id );
if ( function_exists( 'learndash_user_progress_get_first_incomplete_step' ) ) {
$step = (int) learndash_user_progress_get_first_incomplete_step( $user_id, $course_id );
if ( $step && get_post_status( $step ) ) {
$url = function_exists( 'learndash_get_step_permalink' ) ? learndash_get_step_permalink( $step, $course_id ) : get_permalink( $step );
}
}
return '<a class="wpide-ld-resume wp-element-button" href="' . esc_url( $url ) . '">' . esc_html( $atts['label'] ) . '</a>';
} );
Notes
Falls back to the course page when every step is done or the next step cannot be found.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.