# LearnDash: Enroll New Users in Starter Courses

> Automatically enrolls every newly registered user in the LearnDash courses you choose, such as a free onboarding course.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: learndash, enrollment, registration
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/learndash-auto-enroll-new-users/

## Code

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

// Course IDs to enroll new users in.
$wpide_ld_starter_courses = array( 123 );

add_action( 'user_register', function ( $user_id ) use ( $wpide_ld_starter_courses ) {
    foreach ( $wpide_ld_starter_courses as $course_id ) {
        if ( 'sfwd-courses' === get_post_type( $course_id ) ) {
            ld_update_course_access( $user_id, (int) $course_id );
        }
    }
}, 20 );
```

## Notes

Add your course IDs to $wpide_ld_starter_courses. Existing users are not enrolled.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Enroll New Users in Starter Courses" 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/
