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. Custom login form
  31. Adding extra authentication field in login page
  32. How to check in timber if user is loggedin?
  33. Disallowing Users of a Custom Role from Deleting or Adding Administrators?
  34. Stop WordPress from logging me out (need to keep me logged in)
  35. Hide Admin Menu for Specific User ID who has administrator Role
  36. Customize wp_new_user_notification_email()
  37. Need to execute a cron job
  38. Temporarily disable user role login and replace with message
  39. How can I retrieve the username and password from my WordPress installation?
  40. User Directory without a Plugin
  41. Pre checking condition before login
  42. Custom Connect to Facebook, problem logging in/logging out
  43. How can I have different groups of editors only allowed to edit certain parent+subpages?
  44. WordPress login urls
  45. Redirect after empty login username and password
  46. WordPress Login page trashed
  47. Are there ways of logging in that bypass wp-login.php altogether?
  48. Change Favicon on Login Screen?
  49. Customizing the WordPress login form
  50. How to display username and password after registration
  51. wp-login gives 404 error, but wp-admin is working fine
  52. Login error redirecting to wp-login page
  53. access the plugins for each role in WordPress multisite
  54. Password reset – Disabled for LDAP accounts
  55. Replace dash with space in username on login
  56. Autologin only working the second time
  57. Completely replacing the login form
  58. Why wp_update_user doesn’t update user_activation_key on users with apostrophes in their email?
  59. Forgot Password/ Password Reset Page does not exist
  60. WordPress on Apache behind nginx using letsencypt issue with loginizer/limit login attempts
  61. How to create user specific pages (not user role!)?
  62. Auto login between word press subdomain and a .net website
  63. Custom Login form from WordPress site to non-WordPress site
  64. Best option to implement external register/login to WP from self-made API
  65. Plugin creation – how to add user rights?
  66. Enqueue new login style sheet
  67. remove wp admin menu by customer user role
  68. Secure login on wordpress [closed]
  69. Login without Password
  70. Exclude login page from custom maintenance code
  71. Change default login auth
  72. I can’t access my WordPress dashboard – shows Warning message [closed]
  73. Access log “POST /wp-login.php HTTP/1.0” 400
  74. Are login functions considered part of the WP backend?
  75. SQL – Remove All The Users and Create A New User With Admin Role Via PhpMyAdmin
  76. Sharing a logged in session with a custom subdmain site?
  77. MAMP localhost wordpress site, not possible to sign in, username and password are correct
  78. Login issues wordpress page
  79. Make WordPress User Name be the Company Name when Registering (not the default ‘first name’ last name’ email address’)
  80. Why do I have a reauth=1 redirection loop when I try to log in to WordPress hosted on AWS Fargate?
  81. Login form does not store/remember/suggest users password
  82. Problem with is_user_logged_in() function in some pages
  83. Android app – can’t login: “This site already exists in the app, you can’t add it”
  84. Fatal error: Call to undefined function get_plugin_data()
  85. backend access per user status
  86. Make WordPress User Name the Email Address When Register
  87. Users redirected to old site
  88. Save user login date
  89. Login with Username (or Code) only
  90. Enqueue script on logon failure
  91. I get 404 when I try to login ever since I changed the permalink
  92. wp_signon gives error insufficient_permissions
  93. each user having category with their name and can add sub categories post in that category
  94. Is there a way to give users the option to log in to their favorite group on login? [closed]
  95. Direct access to site when log in
  96. Can not login after moving to cloudflare and adding rules
  97. Inconsistent login state
  98. Can i hide a dynamically created div to logged out users?
  99. Why am I not able to login to the admin
  100. WP behind haproxy weirdness
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
  • 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