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 users based on their roles, is_admin()

You could proceed like that :

add_filter("login_redirect", "wpse_113875_login_redirect", 10, 3);
function wpse_113875_login_redirect($redirect_to, $request, $user) {

 if(is_array($user->roles)) 
     if(in_array('administrator', $user->roles)) 
       return site_url('/wp-admin/');

   return home_url();
   }

This will use the WP login system and redirect users according to their role after login. I think this is easier than building your own script in this case. You could easily add some button or link in front-end to the WP login page. Hope this helps.

Related Posts:

  1. is_admin() conditional statement
  2. How to redirect/rewrite all /wp-login requests
  3. Unable to login to my wordpress site. reauth=1 redirection loop
  4. How to Layer 7 Load Balance WordPress Backend and Frontend?
  5. Custom login redirects to wp-admin on wrong password
  6. How to allow users login to WP from external domain and make REST requests
  7. Is there any filter to disable the total fronted in WordPress
  8. Users are redirected to homepage instead of wp-admin
  9. Display sortable User meta column in admin panel user’s page
  10. How to move wp-admin login page to another location? [closed]
  11. Can’t access admin dashboard with wp-admin without /index.php after it
  12. Adding body class to login page?
  13. Edit a WordPress site without the username and password?
  14. WordPress Error establishing a database connection For Admin login only
  15. comment_form – show all fields when logged in
  16. How to use Yoast SEO backend in english even if WPLANG variable is not english?
  17. Using /wp-admin works, using /login gives a 404. Why?
  18. Cannot log into WordPress Dashboard after removing/adding .htaccess
  19. Change WP-Login or WP-Admin
  20. I cannot log into my wordpress site with my wp-login.php [closed]
  21. Why are my frontend theme styles bleeding into the backend?
  22. How do I set the homepage to the WordPress Admin Dashboard login?
  23. Can’t access WordPress as an admin – but I can log in as a user!
  24. Today, without warning, all admin panel logins redirect to home page after login. non-admin users logins work well
  25. Can’t login to Dashboard when changing site URL to HTTPS
  26. Detecting all admins that are logged in
  27. WordPress and bbPress Login conflicts?
  28. I want to disable login of admin (/wp-admin) with email and make it accessible only with username
  29. Website looks fine, but login to wp-admin yields a blank screen
  30. How to make the front-end RTL without changing the admin panel language?
  31. cannot find the login page for local WordPress site
  32. Users disappeared from wp-admin
  33. Modify WP-Admin login fields
  34. display dynamic WP Site logo on wp-admin using CSS
  35. How to Change The WordPress Login URL Without Plugin
  36. wp-admin – 404 after custom login form
  37. How to fix ‘WordPress redirection loop problem in wp-login.php page’?
  38. Logging into sandbox subdomain WP
  39. 404 redirect wp-login and wp-admin after changing login url [closed]
  40. Having troubles connecting to WordPress login page using Mamp
  41. Sorry, you are not allowed to access this page
  42. WP Admin/ WP Login Redirect to themselves
  43. Admin menu in front-end
  44. Cookie Domain is preventing Admin login
  45. Require Login Redirect to Login Page
  46. Cannot access WordPress login pages
  47. Cant login to wp-admin
  48. /wp-admin/ doesn’t work but /admin/ does
  49. Why am I locked out of the system?
  50. Why can I log into wp-login.php and not wp-admin.php?
  51. Disable Admin CP authentication (or auto login)
  52. firing function at login within class
  53. WP-admin or any other is redirecting me to (This page doesn’t seem to exist.)
  54. wp-login not found – All usual solutions not working
  55. how can provide access to wp_admin page for non wp_users?
  56. Can’t connect to WP-Admin, blank error message
  57. Blank page when viewing wp-admin
  58. GoDaddy hosting wp-admin problem
  59. WP Admin Login keeps redirecting to login
  60. CPU overload spam – redirect link to wp-admin and new post
  61. define two login page url
  62. Login issue with subdomain installs
  63. How can I can I make changes to a WP project I pulled from GItHub?
  64. WordPress Admin Login Issue
  65. How to log into WordPress via GET/POST
  66. wp-login.php entering password nothing happens
  67. Trying to login to my site redirects me to the first page
  68. stop customize.php redirect to login page if admin is not logged in
  69. Admin Login Checks
  70. WordPress logged in but no access to wp-admin
  71. Changed the path to wp-login and now can’t access WPress dashboard
  72. Unable to log in as admin
  73. Why my login panel has a wrong language?
  74. Handling multiple account logins?
  75. Not able to access WP admin Page, redirected and a drop down login menu appears 401 error
  76. WordPress Login for multiple sites
  77. Cannot login in WordPress even after changing hash password in phpmyadmin
  78. Can’t log into WordPress after domain change
  79. Why WordPress not logout after I have close my browser?
  80. Admin Login page not working at all
  81. plugin: ‘init’ hook, check if we’re not in admin
  82. Impossible User Registration
  83. Couple questions about .htaccess, login page, updates
  84. After Upgrade: $user becomes unknown (id: 0) after successful login?
  85. WordPress site shows a white page for site/wp_admin. A login returns again to the login screen
  86. Admin access to secondary site user_can_access_admin_page losing login
  87. login_enqueue_scripts changes are not reflecting
  88. Renaming wp-admin without hard-coding it. Is it really possible?
  89. Admin login not working
  90. add_submenu_page() issue
  91. how to stop wordpress admin menu from scrolling with page
  92. How to have WP admin in English while public website is in another language?
  93. only last option from theme options is being saved to the DB
  94. Cached php? Updates are rendering only if logged as admin
  95. Symlinking WordPress WP-ADMIN and WP-INCLUDES
  96. Admin Scripts enqueue codes seems ok but not working
  97. admin-post.php results on white screen after form submission
  98. How to protect wp-admin from third party access?
  99. Extend user search in the Wp backend area on the users.php page to allow for searching by email domain and role from the “users search” input box
  100. Is there a way to get the WP Admin Header to inject as the first element in the body instead of the last?
Categories wp-admin Tags front-end, login, wp-admin
Override default options in plugin metaboxes
checking the form submit in right order

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