# LearnDash: Show Students When Their Course Access Expires

> Shows a notice at the top of course, lesson and topic pages telling enrolled students the date their access ends, for courses that use access expiration.

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

## Code

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

add_filter( 'the_content', function ( $content ) {
    if ( ! is_singular( array( 'sfwd-courses', 'sfwd-lessons', 'sfwd-topic' ) ) || ! in_the_loop() || ! is_user_logged_in() ) {
        return $content;
    }

    $course_id = (int) learndash_get_course_id( get_the_ID() );
    $expires   = $course_id ? (int) ld_course_access_expires_on( $course_id, get_current_user_id() ) : 0;

    if ( ! $expires || $expires < time() ) {
        return $content;
    }

    $soon   = $expires - time() < 7 * DAY_IN_SECONDS;
    $notice = sprintf(
        '<p class="wpide-ld-expiry%1$s" role="status" style="padding:.6em 1em;border-left:4px solid %2$s;background:rgba(127,127,127,.08)">%3$s</p>',
        $soon ? ' is-soon' : '',
        $soon ? '#d63638' : '#2271b1',
        esc_html( sprintf( 'Your access to this course ends on %s.', wp_date( get_option( 'date_format' ), $expires ) ) )
    );

    return $notice . $content;
}, 5 );
```

## Notes

Only shows for courses with "Expire access" turned on. The notice turns into a warning in the last 7 days.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Show Students When Their Course Access Expires" 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/
