# LearnDash: Redirect Students After They Finish a Course

> Sends students to a page of your choice (a thank-you page, survey or upsell) the next time they load a page after completing a LearnDash course.

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

## Code

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

// Course ID => URL. "default" applies to all other courses.
$wpide_ld_done_pages = array(
    'default' => home_url( '/thank-you/' ),
);

add_action( 'learndash_course_completed', function ( $data ) use ( $wpide_ld_done_pages ) {
    $course_id = isset( $data['course']->ID ) ? (int) $data['course']->ID : 0;
    $user_id   = isset( $data['user']->ID ) ? (int) $data['user']->ID : 0;
    $url       = $wpide_ld_done_pages[ $course_id ] ?? ( $wpide_ld_done_pages['default'] ?? '' );

    if ( $user_id && $url ) {
        update_user_meta( $user_id, 'wpide_ld_done_redirect', esc_url_raw( $url ) );
    }
} );

add_action( 'template_redirect', function () {
    $user_id = get_current_user_id();
    $url     = $user_id ? get_user_meta( $user_id, 'wpide_ld_done_redirect', true ) : '';

    if ( $url ) {
        delete_user_meta( $user_id, 'wpide_ld_done_redirect' );
        wp_safe_redirect( $url );
        exit;
    }
} );
```

## Notes

Map course IDs to pages in $wpide_ld_done_pages; the "default" entry is used for every other course. Leave it empty to only redirect the courses you list.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Redirect Students After They Finish a Course" 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/
