LifterLMS: Body Classes for Enrollment Status
Adds body classes such as wpide-llms-enrolled or wpide-llms-completed on course and lesson pages so you can tailor the design for each student.
Opens WPIDE on
Code
if ( ! function_exists( 'llms_get_student' ) ) {
return;
}
add_filter( 'body_class', function ( $classes ) {
if ( ! is_singular( array( 'course', 'lesson' ) ) ) {
return $classes;
}
$post_id = get_queried_object_id();
$course_id = 'lesson' === get_post_type( $post_id ) ? (int) get_post_meta( $post_id, '_llms_parent_course', true ) : $post_id;
$student = llms_get_student();
if ( ! $student ) {
$classes[] = 'wpide-llms-guest';
} elseif ( ! $course_id || ! $student->is_enrolled( $course_id ) ) {
$classes[] = 'wpide-llms-not-enrolled';
} else {
$classes[] = 'wpide-llms-enrolled';
if ( $student->is_complete( $course_id, 'course' ) ) {
$classes[] = 'wpide-llms-completed';
}
}
return $classes;
} );
Notes
Classes: wpide-llms-guest, wpide-llms-not-enrolled, wpide-llms-enrolled, wpide-llms-completed.
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.