LifterLMS: Send Students to Their Dashboard After Login
Sends students who log in through wp-login.php to the LifterLMS student dashboard instead of the WordPress admin profile.
Opens WPIDE on
Code
if ( ! function_exists( 'llms_get_page_url' ) ) {
return;
}
add_filter( 'login_redirect', function ( $redirect, $requested, $user ) {
if ( ! $user instanceof WP_User || user_can( $user, 'edit_posts' ) ) {
return $redirect;
}
if ( $requested && false === strpos( $requested, admin_url() ) ) {
return $redirect;
}
$dashboard = llms_get_page_url( 'myaccount' );
return $dashboard ? $dashboard : $redirect;
}, 10, 3 );
Notes
Staff who can edit posts still go to wp-admin, and an explicit redirect_to link is respected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.