# 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.

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

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LifterLMS: Content Only for Enrolled Students" 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/
