Redirect Users on Their First Login
Sends each user to a welcome or onboarding page the first time they log in, and to the usual place after that.
Opens WPIDE on
Code
// Where first-time users go.
$wpide_first_login_url = home_url( '/welcome/' );
add_filter( 'login_redirect', function ( $redirect_to, $requested, $user ) use ( $wpide_first_login_url ) {
if ( ! ( $user instanceof WP_User ) || get_user_meta( $user->ID, 'wpide_first_login_done', true ) ) {
return $redirect_to;
}
update_user_meta( $user->ID, 'wpide_first_login_done', time() );
return $wpide_first_login_url;
}, 30, 3 );
Notes
Existing users count as first-timers on their next login after you activate this.
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.