# LearnDash: Body Classes for Course Status

> Adds body classes such as wpide-ld-enrolled and wpide-ld-completed on course, lesson and topic pages, so you can style or hide things with CSS depending on the student's status.

- Type: PHP
- Runs: Frontend only
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: learndash, css, body-class
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/learndash-course-completed-body-class/

## Code

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

add_filter( 'body_class', function ( $classes ) {
    if ( ! is_singular( array( 'sfwd-courses', 'sfwd-lessons', 'sfwd-topic', 'sfwd-quiz' ) ) ) {
        return $classes;
    }

    $user_id   = get_current_user_id();
    $course_id = (int) learndash_get_course_id( get_queried_object_id() );

    if ( ! $user_id ) {
        $classes[] = 'wpide-ld-guest';
    } elseif ( ! $course_id || ! sfwd_lms_has_access( $course_id, $user_id ) ) {
        $classes[] = 'wpide-ld-not-enrolled';
    } else {
        $classes[] = 'wpide-ld-enrolled';

        if ( learndash_course_completed( $user_id, $course_id ) ) {
            $classes[] = 'wpide-ld-completed';
        }
    }

    return $classes;
} );
```

## Notes

Classes: wpide-ld-guest, wpide-ld-not-enrolled, wpide-ld-enrolled and wpide-ld-completed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Body Classes for Course Status" 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/
