# LearnDash: Add New Users to a Group

> Puts every newly registered user into a LearnDash group automatically, giving them the group's courses and placing them under its group leaders.

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

## Code

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

// LearnDash group ID.
$wpide_ld_new_user_group = 0;

add_action( 'user_register', function ( $user_id ) use ( $wpide_ld_new_user_group ) {
    if ( $wpide_ld_new_user_group && 'groups' === get_post_type( $wpide_ld_new_user_group ) ) {
        ld_update_group_access( $user_id, $wpide_ld_new_user_group );
    }
}, 20 );
```

## Notes

Set the group ID at the top. Users created by an administrator are included too.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Add New Users to a Group" 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/
