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 Login Based on User Role

function dashboard_redirect($url, $request, $user) {
   
    if (in_array('test_user_role', (array) $user->roles)) {
        $url = admin_url('users.php');
    }else{
        $url = admin_url('index.php');
    }

    return $url;
}

add_filter('login_redirect', 'dashboard_redirect', 10, 3);  

The user can be passed into your function with a little more argument specificity.

Related Posts:

  1. Is possible to allow user to login with different role?
  2. If the current user is an administrator or editor
  3. Editor can create any new user except administrator
  4. How to allow an user role to create a new user under a role which lower than his level only?
  5. Remove Ability for Other Users to View Administrator in User List?
  6. Find out if logged in user is not subscriber
  7. Groups of capabilities: users with multiple roles?
  8. User-edit role setting distinct from wp_capabilities? [closed]
  9. Allowing users to edit only their page and nobody else’s
  10. alphabetically order role drop-down selection in dashboard
  11. Execute a function when admin changes the user role
  12. How to let contributors to create a new revision(draft) editing their published posts
  13. Disallowing Users of a Custom Role from Deleting or Adding Administrators?
  14. What the user_status column?
  15. Hide Admin Menu for Specific User ID who has administrator Role
  16. How to hide media uploads by other users in the Media menu?
  17. Show admin bar only for some USERS roles
  18. Grouping users under parent user
  19. How to update user role without logout
  20. How to check user role without using current_user_can()
  21. Multi-steps WordPress registration : in 4 steps how to?
  22. Do not allow users to create new posts and pages
  23. \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
  24. How to enable the theme editor cap for an editor role?
  25. How to assign capabilities to user NOT to User Role
  26. How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
  27. How to stop a user from updating the post date
  28. BuddyPress | Check if user is in current group [closed]
  29. Return ID of authors who have at least one post
  30. WordPress edit_user_profile_update update secondary role
  31. How do I properly format the user_role array?
  32. How-to Delay The Capability To Publish Posts?
  33. How to customize wp_signon()
  34. Is there a simple way to manage capabilities per user?
  35. Is it possible to get a user with just the password field?
  36. How to get the Role Name of the current user? (WordPress)
  37. Redirect after login based on user role (custom login page)
  38. set_role has no effect
  39. WP_User->add_role producing unexpected results
  40. How can I check if the admin bar is visible to the current user?
  41. Can I create users that have access to *some* other users posts instead of all other users posts?
  42. Set default page for user account in admin
  43. Users roles, make a page belonging to multiple users
  44. Tagging users in WordPress
  45. Redirect after users complete profile form
  46. How do I list in the backend all users that were assigned to a custom role?
  47. How to add local users to wordpress without email password?
  48. Hide everything on site for visitors except specific page IDs
  49. Get User Role by ID not working
  50. the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
  51. Getting users by specific capability, not role
  52. add_cap not working with Shop Manager role
  53. wp_login_form() passing user ID into URL on redirect?
  54. Managing Users and Creating Groups [closed]
  55. How to disable a specific page for a specific user
  56. Are User Levels Still Currently Used?
  57. Error: How to allow the “contributor” to upload media in wordpress
  58. Remove Capabilities from WP admin for specific user role
  59. Updating wp_user_level on user update
  60. wordpress user roles are not working
  61. Displaying different in-page content to cliente/admin
  62. Fix permissions for users role
  63. User capability for editing their own comments
  64. What are some best practices for user exit strategy?
  65. Is there a way to identify a user in a custom REST API method? [duplicate]
  66. Problem with automatic role change through cron job
  67. Allow Contributors to Upload Files
  68. How can I allow an User to publish only 5 posts per month?
  69. Add a role and give admin priviledges
  70. Where are $current_user->allcaps set?
  71. How change user type from contributor to author
  72. WP not logging in at first time
  73. How do I let contributors edit their posts after being approved once?
  74. Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
  75. How can I prevent certain custom roles from seeing other custom roles on the user list page?
  76. How many people are allowed to use same wordpress account at the same time?
  77. Restrict access to non-wordpress section of site with user roles?
  78. Load user by specific role
  79. What’s the correct way to add capabilites to user roles?
  80. How to hide user profile fields based on the role of the viewed user?
  81. Fix ‘Add Role’ Option not there in wordpress 5.2.2
  82. User roles not displaying
  83. Allow admins to login as other users
  84. Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
  85. Can I Create a Second Admin Level User Role?
  86. Does it matter if the very first user, usually Admin, does not have a user ID of 1?
  87. Customising “user ids” and add to ‘user’ panel in the admin area
  88. How to hide some users to unlogged users [closed]
  89. List all users and current week entries
  90. Groups and subgroups for permission
  91. Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
  92. Change User Role based on Point System Issue
  93. how do I add role and capability after I create a new user
  94. Get Authors Role
  95. How do I modify the user role ‘subscriber’ to allow the user to delete posts
  96. WordPress user role with create user capability?
  97. Editor role can only create/edit/delete users who have one of two roles
  98. User can’t search himself on rest api
  99. Update user role for expired membership
  100. How to allow access based on the user meta flag
Categories users Tags user-roles, users, wp-login-form
Display posts of only a certain category in WP Admin section?
How to get WordPress to ignore the search parameter in the frontend?

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