Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Redirect after login based on user role (custom login page)

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:

  1. Is it possible to get a user with just the password field?
  2. Is possible to allow user to login with different role?
  3. Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
  4. If the current user is an administrator or editor
  5. Editor can create any new user except administrator
  6. How to allow an user role to create a new user under a role which lower than his level only?
  7. Remove Ability for Other Users to View Administrator in User List?
  8. Find out if logged in user is not subscriber
  9. Groups of capabilities: users with multiple roles?
  10. User-edit role setting distinct from wp_capabilities? [closed]
  11. Replacing the WordPress password validation
  12. Allowing users to edit only their page and nobody else’s
  13. alphabetically order role drop-down selection in dashboard
  14. WordPress auto login after registration not working
  15. Execute a function when admin changes the user role
  16. How to let contributors to create a new revision(draft) editing their published posts
  17. Disallowing Users of a Custom Role from Deleting or Adding Administrators?
  18. What the user_status column?
  19. Hide Admin Menu for Specific User ID who has administrator Role
  20. Allow up to 5 Concurrent Login Sessions
  21. How to hide media uploads by other users in the Media menu?
  22. Show admin bar only for some USERS roles
  23. Grouping users under parent user
  24. How to update user role without logout
  25. How to check user role without using current_user_can()
  26. Why does is_user_logged_in() return false after redirect from another site?
  27. Do not allow users to create new posts and pages
  28. How to redirect a specific user after log-in?
  29. \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
  30. Force users to complete their profile after they register? How to
  31. How to enable the theme editor cap for an editor role?
  32. How to assign capabilities to user NOT to User Role
  33. How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
  34. How to stop a user from updating the post date
  35. BuddyPress | Check if user is in current group [closed]
  36. Pre-populate Username Field
  37. Return ID of authors who have at least one post
  38. WordPress edit_user_profile_update update secondary role
  39. How to keep track of user logins?
  40. How do I properly format the user_role array?
  41. How-to Delay The Capability To Publish Posts?
  42. Get user info outside WordPress
  43. How can I secure a WordPress blog using OpenID from a single provider?
  44. How to customize wp_signon()
  45. Is there a simple way to manage capabilities per user?
  46. How to get the Role Name of the current user? (WordPress)
  47. set_role has no effect
  48. Check for user meta data at Login
  49. WP_User->add_role producing unexpected results
  50. How can I check if the admin bar is visible to the current user?
  51. Redirect User to Homepage if no other redirect is specified
  52. Can I create users that have access to *some* other users posts instead of all other users posts?
  53. My custom page template with is_user_logged_in() does not detect that I’m logged in
  54. Set default page for user account in admin
  55. Use phpbb user database for WordPress
  56. WordPress to use Drupal users’ credentials
  57. Users roles, make a page belonging to multiple users
  58. Tagging users in WordPress
  59. Redirect after users complete profile form
  60. Share user table from WP with Drupal
  61. How do I list in the backend all users that were assigned to a custom role?
  62. How can I allow password reset based on logins containing the @ character?
  63. A way to count logged in users and display count?
  64. stop login if user_status equal zero
  65. How to add local users to wordpress without email password?
  66. Hide everything on site for visitors except specific page IDs
  67. Get User Role by ID not working
  68. the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
  69. Getting users by specific capability, not role
  70. add_cap not working with Shop Manager role
  71. Restricting frontend acess based on user role otherwise redirect to login form
  72. How do i make my wordpress website private?
  73. Managing Users and Creating Groups [closed]
  74. Redirect user to login before viewing custom post
  75. Change the user_login at registration
  76. How to disable a specific page for a specific user
  77. Are User Levels Still Currently Used?
  78. Max no of simultaneous active sessions for a single user
  79. Error: How to allow the “contributor” to upload media in wordpress
  80. Remove Capabilities from WP admin for specific user role
  81. When I try to login in wordpress it is showing “USER Doesn’t Exists”
  82. Updating wp_user_level on user update
  83. wordpress user roles are not working
  84. Displaying different in-page content to cliente/admin
  85. Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
  86. Fix permissions for users role
  87. Redirect subscribers to last viewed page after log-in
  88. User capability for editing their own comments
  89. What are some best practices for user exit strategy?
  90. Is there a way to identify a user in a custom REST API method? [duplicate]
  91. wordpress disable login for unverified user
  92. Problem with automatic role change through cron job
  93. Reset Password policy
  94. Allow Contributors to Upload Files
  95. Rewrite Rules and Login Issue
  96. How can I allow an User to publish only 5 posts per month?
  97. Add a role and give admin priviledges
  98. Where are $current_user->allcaps set?
  99. How change user type from contributor to author
  100. Use WordPress Login for a non-wordpress site
Categories users Tags login, user-roles, users, wp-redirect
Custom Taxonomy not showing as option on custom post page
is_page(id) not working for blog page

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress