# LearnDash: Course Status Badge Shortcode

> Adds a [wpide_ld_status] shortcode that shows a small "Not started", "In progress" or "Completed" badge for the current student and course.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: learndash, shortcode, progress
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/learndash-course-status-badge/

## Code

```php
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
    return;
}

add_shortcode( 'wpide_ld_status', function ( $atts ) {
    $atts      = shortcode_atts( array( 'course_id' => 0 ), $atts, 'wpide_ld_status' );
    $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 '';
    }

    $progress = learndash_course_progress( array( 'user_id' => $user_id, 'course_id' => $course_id, 'array' => true ) );
    $percent  = (int) ( $progress['percentage'] ?? 0 );

    if ( learndash_course_completed( $user_id, $course_id ) || $percent >= 100 ) {
        $state = array( 'is-completed', 'Completed' );
    } elseif ( $percent > 0 ) {
        $state = array( 'is-in-progress', 'In progress' );
    } else {
        $state = array( 'is-not-started', 'Not started' );
    }

    return '<span class="wpide-ld-status ' . esc_attr( $state[0] ) . '" style="display:inline-block;padding:.15em .6em;border-radius:999px;border:1px solid currentColor;font-size:.85em">' . esc_html( $state[1] ) . '</span>';
} );
```

## Notes

Style it with the classes .wpide-ld-status.is-not-started, .is-in-progress and .is-completed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Course Status Badge Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
