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

WordPress Login redirection according to user role

You’re using the filter wrong. If you got more than one @param, then you have to state them when adding the filter.

function wpse40745_redirect_on_login( $redirect_to, isset( $_REQUEST['redirect_to'] ), $user )
{
    # uncomment the following line if it's not working and replace $user->roles[0] with something that works
    // echo '<pre>'; print_r( $user ); echo '</pre>'; exit;

    if ( in_array( $user->roles[0], array( 'contributer', 'whatever_other_role ) ) )
        return home_url();

    return $redirect_to;
}
add_filter( 'login_redirect', 'wpse40745_redirect_on_login', 20, 3 );

Related Posts:

  1. Custom user roles are unable to login
  2. Separate registration and login for different roles
  3. Disallow user from editing their own profile information
  4. Website Visible only to Registered users
  5. moving server can not login
  6. how to update current logged user username
  7. How can I allow access to two user accounts using one login?
  8. Redirecting or displaying a message on first login
  9. Restricting frontend acess based on user role otherwise redirect to login form
  10. Deny a user role to log in after register
  11. Private page protected with username and password
  12. Password protect media attachment – share across guests
  13. How to integrate external user tables with WP?
  14. Allow Users Only Edit Their Profile?
  15. WordPress login problem
  16. Set Default User Role
  17. Lock out all WordPress Administrators except two specific users
  18. Generate email on meta value update
  19. Prevent Subscriber Role to login
  20. How to restrict access to a single for users I’ve authorized? [closed]
  21. Can I protect a type of content site-wide with a single password?
  22. Sign in with social media accounts without creating a WP account [closed]
  23. Login Based on ip
  24. URL Restrictions? Need only people who are logged in AND have a specific role (or roles) to access all pages for a site
  25. Custom failed login error messages for users based on user role?
  26. How to show private pages based on a user’s role?
  27. How to password protect pages in WordPress
  28. How to lock WordPress front-end with login and password?
  29. Creating Custom Login Form Where Password Field is Dropdown Menu
  30. WordPress change role from administrator to author by itself (automatically)
  31. In Django, how do I know the currently logged-in user?
  32. Can I programmatically login a user without a password?
  33. Allow member to have access to custom post type only. Permission to only edit their own posts
  34. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  35. Is there any way to rename or hide wp-login.php?
  36. How to login with email only no username?
  37. How can I redirect user after entering wrong password?
  38. Increase of failed login attempts, brute force attacks? [closed]
  39. Login page ERROR: Cookies are blocked due to unexpected output
  40. SSO / authentication integration with external ‘directory service’
  41. Preventing session timeout
  42. How reduce wordpress login session timeout time?
  43. How to prefill WordPress registration with social details
  44. Check for correct username on custom login form
  45. I can’t access my site via wp-admin
  46. ‘Password field is empty’ error when using autofill in Chrome
  47. Removing username from the ‘wordpress_logged_in’ cookie
  48. How to show ‘login error’ and ‘lost password’ on my template page?
  49. What is $interim_login?
  50. Custom login form
  51. How to prefill the username/password fields on the login page
  52. wp_signon returns user, but the user is not logged in
  53. wp_update_user not updating
  54. Adding extra authentication field in login page
  55. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  56. Allowing users to edit only their page and nobody else’s
  57. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  58. wp_signon() does not authenticate user guidance needed
  59. What exactly is ReAuth?
  60. What are the differences between wp_users and wp_usermeta tables?
  61. Login members using web services
  62. Make my wordpress blog remember my login “forever”
  63. Troubleshooting a “You do not have sufficient permissions to access this page” error
  64. How to check in timber if user is loggedin?
  65. Restrict admin access to certain pages for certain users
  66. How do I change the language of only the login page?
  67. How can I hide a category from Contributors in the edit/add new post screen?
  68. Disallowing Users of a Custom Role from Deleting or Adding Administrators?
  69. Disable WordPress 3.6 idle logout / login modal window / session expiration
  70. Stop WordPress from logging me out (need to keep me logged in)
  71. Woocommerce registration page [closed]
  72. How to disable autocomplete on the wp-login.php page
  73. Share login data/cookies between multiple installations
  74. How to assign specific users the capability to edit specific pages / posts / custom post types
  75. Hide Admin Menu for Specific User ID who has administrator Role
  76. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  77. How to pass users back and forth using session data?
  78. How do I change the logo on the login page?
  79. Why does WordPress hide the reset password key from the URL?
  80. Is it possible to sign in with user_email in WordPress?
  81. How to get all capabilities of an existing user role
  82. How to use current_user_can()?
  83. Avoid to load default WP styles in login screen
  84. WordPress registration message
  85. Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
  86. How to fake a WordPress login?
  87. Limit access to posts/pages by user roles
  88. how to display the wordpress login and register forms on a page?
  89. Does wp_logout_url() destroy a session? (Logging out question)
  90. How can I send a welcome email to a user AFTER they login for the first time?
  91. Can not login with correct username and password
  92. Is WordPress’ is_user_logged_in() secure?
  93. How can i increase the login expiration length?
  94. How do I use add_action from a class method?
  95. How to remove the WordPress logo from login and register page?
  96. How can I add a custom script to footer of login page?
  97. Brute force attack?
  98. Customize wp_new_user_notification_email()
  99. Need to execute a cron job
  100. Login email after registration never sent or received
Categories login Tags login, user-access, user-roles
Create an archive listing based on meta array
Post editor is 89953px tall. How to fix?

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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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