Try this. It works for me.
add_filter( 'login_redirect', 'redirect_non_admin_to_dashboard'), 10, 3 );
function redirect_non_admin_to_dashboard($redirect_to, $requested_redirect_to, $user ) {
global $user;
if( ! isset( $user->ID ) ) {
return $redirect_to;
}
if ( ! in_array( 'author', (array) $user->roles ) ) {
$redirect_to = site_url().'/dashboard-teacher';
}elseif( in_array( 'subscriber',(array) $user->roles ) ){
$redirect_to = site_url().'/dashboardwwp-student';
}else{
$redirect_to = site_url();
}
return wp_validate_redirect( $redirect_to, home_url() ); // return a safe redirect url between the site.
}
Related Posts:
- Is it possible to get a user with just the password field?
- Is possible to allow user to login with different role?
- Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
- Editor can create any new user except administrator
- How to allow an user role to create a new user under a role which lower than his level only?
- Remove Ability for Other Users to View Administrator in User List?
- Replacing the WordPress password validation
- Allowing users to edit only their page and nobody else’s
- alphabetically order role drop-down selection in dashboard
- WordPress auto login after registration not working
- How to let contributors to create a new revision(draft) editing their published posts
- Allow up to 5 Concurrent Login Sessions
- How to hide media uploads by other users in the Media menu?
- Show admin bar only for some USERS roles
- How to check user role without using current_user_can()
- How to redirect a specific user after log-in?
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- How to assign capabilities to user NOT to User Role
- How to stop a user from updating the post date
- BuddyPress | Check if user is in current group [closed]
- Pre-populate Username Field
- Return ID of authors who have at least one post
- WordPress edit_user_profile_update update secondary role
- How to keep track of user logins?
- How-to Delay The Capability To Publish Posts?
- How to get the Role Name of the current user? (WordPress)
- WP_User->add_role producing unexpected results
- How can I check if the admin bar is visible to the current user?
- Redirect User to Homepage if no other redirect is specified
- Can I create users that have access to *some* other users posts instead of all other users posts?
- My custom page template with is_user_logged_in() does not detect that I’m logged in
- Set default page for user account in admin
- Tagging users in WordPress
- Share user table from WP with Drupal
- Hide everything on site for visitors except specific page IDs
- Get User Role by ID not working
- the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
- add_cap not working with Shop Manager role
- Restricting frontend acess based on user role otherwise redirect to login form
- Managing Users and Creating Groups [closed]
- Redirect user to login before viewing custom post
- Max no of simultaneous active sessions for a single user
- Updating wp_user_level on user update
- Fix permissions for users role
- Redirect subscribers to last viewed page after log-in
- How can I allow an User to publish only 5 posts per month?
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- How change user type from contributor to author
- Use WordPress Login for a non-wordpress site
- WordPress Login Customization for External Authentication
- Is there any action /filter hook I can use to disable login for some user role?
- Display video on homepage for users who have not logged in
- How many people are allowed to use same wordpress account at the same time?
- Restrict access to non-wordpress section of site with user roles?
- How to hide user profile fields based on the role of the viewed user?
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Can I Create a Second Admin Level User Role?
- How can i login with user’s password in WordPress being an admin?
- Does it matter if the very first user, usually Admin, does not have a user ID of 1?
- Customising “user ids” and add to ‘user’ panel in the admin area
- How to hide some users to unlogged users [closed]
- List all users and current week entries
- Use members from 1 site on another one
- Can I edit the database to change a login?
- how redirect users to custom login page when “login to reply” is clicked? [duplicate]
- User(s) already exists show error please provide a valid username
- how do I add role and capability after I create a new user
- Get Authors Role
- WordPress user role with create user capability?
- Editor role can only create/edit/delete users who have one of two roles
- User can’t search himself on rest api
- Restricting wordpress login sessions for a web app
- Update user role for expired membership
- Find count of WordPress users by role and search string for user name
- How to connect wordpress user with my own APP user?
- Hook into add_user_role and update based on new and removed roles
- How to Moderate Edits to User Profiles?
- fine-grained capabilities for user related capabilities
- Check for empty username or password on login
- Create relationships between users or user roles
- Updated user role inncorrect when using wp_get_current_user()
- User Permissions on custom post type
- Custom User Role: Can Edit Own Page, Cannot Create New
- Show user details only
- Specific Content on pages based on user
- WordPress install checking permissions of user id 0
- Access level seems to have gone from admin to editor
- custom login form, guide me
- Front end login and page restriction
- Limit roles displayed in users.php depending on custom role
- Creating Custom user type just like custom post
- Redirect based on log-in status per JavaScript
- Control Category of each user can post
- i need to let a user to add a role from a frontend form
- Integrating Facebook Registration (and Login) on a WordPress page
- current_user_can() returning true for capability when the user and role do not have the capability
- How to create a specific role to manage users
- How to track all users logged into a site?
- Cant edit profile from frontend