LifterLMS: Content Only for Enrolled Students
Adds a [wpide_llms_enrolled id="123"] shortcode that shows its content only to students enrolled in a course or membership, with an optional message for everyone else.
Opens WPIDE on
Code
if ( ! function_exists( 'llms_is_user_enrolled' ) ) {
return;
}
add_shortcode( 'wpide_llms_enrolled', function ( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'id' => 0, 'message' => '' ), $atts, 'wpide_llms_enrolled' );
$id = absint( $atts['id'] );
$user_id = get_current_user_id();
if ( $id && $user_id && ( llms_is_user_enrolled( $user_id, $id ) || current_user_can( 'edit_post', $id ) ) ) {
return do_shortcode( $content );
}
return $atts['message'] ? '<p class="wpide-llms-locked">' . esc_html( $atts['message'] ) . '</p>' : '';
} );
Notes
Example: [wpide_llms_enrolled id="123" message="Enroll to download the workbook."]Download link[/wpide_llms_enrolled].
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.