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

Send admin to a different login than users?

You can do this using login_redirect filter.

function my_login_redirect( $redirect_to, $request, $user ) {
    global $user;
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check for admins
        if ( in_array( 'administrator', $user->roles ) ) {
            // redirect them to the default place
            //make wp-admin as your default place, if you customized it
            return $redirect_to;
        } else {
            return home_url('/login/');
        }
    } else {
        return $redirect_to;
    }
}

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

UPDATE

I am assuming that you are using wp_login_form for the custom login page and already hooked to authenticate to handle empty username and/or password issue.

We can use $_SERVER['HTTP_REFERER'] to check from where the request came from and redirect accodringly.

function wpse9845_my_awesome_login_fail( $username ) {
   $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
   // if there's a valid referrer, and it's not the default wp-login.php ot wp-admin screen
   if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
      wp_redirect( $referrer );
      exit;
   }
}
add_action( 'wp_login_failed', 'wpse9845_my_awesome_login_fail' );

There’s a bad side of the above code: $_SERVER['HTTP_REFERER'] is not supported by all user agent.

Note(from php.net): HTTP_REFERER – The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Best way to do this is using a completely custom login page/form, along with authentication. Here is a very good tutorial.

Related Posts:

  1. Admin login not working
  2. Remove iPhone detection on login page
  3. WordPress login process is hanging
  4. How to Change the Default Home Page for the WordPress Dashboard?
  5. The website cannot display the page
  6. Are there any action like ‘init_frontend’
  7. Cannot access admin panel
  8. Is there a hook to put stylesheet and/or JS inside iframes (thickbox or tinyMCE) in admin area
  9. A similar hook as wp_head for the admin area
  10. Daily notices of failed login attempts for non-existent admin user
  11. How can I do customizations on login, registration and password recovery forms?
  12. How to Remove the “Restore” Link in Quick Edit?
  13. Use latest jQuery in WordPress (admin interface)
  14. Setting Login with User Name and Password default option for Jetpack Admin Login
  15. Check if user is logged in else login page
  16. I keep getting logged out in Firefox
  17. Adding markup to column text in “Edit Pages” admin page
  18. Error thrown. Cannot create references to/from string offsets
  19. Disable HTML (Text) Tab in Post Editor
  20. How to determine if an admin is logged in outside the loop
  21. Change username before login
  22. Manage users custom column add class “num”
  23. Unable to login, old site with previous developer gone
  24. Custom Thickbox Broken on Dashboard Page?
  25. Where should I hook into admin?
  26. Using shared SSL for login/admin
  27. wp-login behind nginx reverse-proxy inaccessible — bad redirect?
  28. Can’t access dashboard as administrator, login as any other level works though
  29. WordPress Admin Login Redirect Problem
  30. Problems with WP_List_Table and hooks
  31. Unable to Access WP Admin or Login buttons after Migration
  32. using rewrites to secure login page
  33. Client system for media review?
  34. WordPress administration Over SSL – To Force SSL Logins and SSL Admin Access
  35. Keep Logged in Users out of Admin Panel
  36. Why can’t a custom postype be registered with “admin_init” hook?
  37. Remove Permalink From Admin Edit Post
  38. Show excerpt if no title in admin view
  39. Seems that admin_post_{action} does not executing
  40. Unable to get to the admin panel
  41. get_current_screen and the WP_Screen class
  42. I can’t access the login panel on my offline website
  43. Filter WooCommerce Orders
  44. Can’t login to my admin area
  45. Does deleting the table users prevent all logins?
  46. Locked out of WordPress website from wrong amount of login attempts
  47. current_user_can(‘administrator’) not working in custom login
  48. Want to know who is login Admin/User
  49. Any known plugins for master admin login to edit all on front end?
  50. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  51. Login to admin by frontend form?
  52. Error “Sorry, you are not allowed to access this page”
  53. I can’t access login page
  54. Redirect non-admin after login, and in url – /admin
  55. Admins loggin in to our wordpress site default to the admin page
  56. ‘Conflict’ with action deleted_post and is_admin()
  57. How to change the title attribute for the WP logo image on wp-login.php
  58. WordPress login not working
  59. Login to Admin Dashboard Problem
  60. WordPress “Hide WP” Gives Me Error After Admin Login [closed]
  61. Scripts are not called until I login from wordpress backend
  62. Disable wp-admin log on lightbox overlay
  63. How to cancel redirection to admin side
  64. How to add a new link to the default register form’s footer links?
  65. Can’t access my wp admin: captcha images invisible, gives me error message
  66. You do not have permission to access this document on form submit
  67. Different customer login form than administrator login form?
  68. 2FA for admin login only, is it doable?
  69. how to know if admin is in edit page or post [duplicate]
  70. How can ‘admin_email’ be set?
  71. How to change WordPress default strings?
  72. Remove ability to access certain admin menus
  73. Gutenberg “Add Block” button is not active (greyed out), cannot add new blocks
  74. How can I tell if I’m on a login page? [duplicate]
  75. How to customise wp-login.php only for users who are setting a password for the first time?
  76. Wrong url in sortable column headers & pagination in the admin, when behind a proxy
  77. Add tabbed menu to admin page
  78. WordPress login with Phone Number [closed]
  79. How can I restore admin capabilities?
  80. What determines whether admin toolbar is shown to a logged-in user?
  81. Remove Order List Row Link in WooCommerce Admin?
  82. How to disable https from wordpress site?
  83. Apply permissions per post
  84. Is possible to allow user to login with different role?
  85. Unable to upload image using the standard uploader in the WP admin (v4.3)
  86. When submitting the form site.com/blog/wp-admin it goes to site.com/wp-admin
  87. I’m a super admin and I want to give an admin the ability to add new users…?
  88. Order All Pages table in administration
  89. Load stylesheet on custom admin submenu page
  90. How can all E-mails be sent with BCC copy to Admin?
  91. Show admin bar to editors with Buddypres
  92. Login redirects to home page and doesn’t log in
  93. Disabling “View” mentions from backend?
  94. Handle logo text color from admin section
  95. Exclude admin from the top commenters list [duplicate]
  96. Troubleshooting white screen when editing specific posts
  97. Private messaging plugins + custom admin
  98. Does wp_login hook fire on user registration?
  99. How to authenticate/verify login credentials & check for user meta without logging in?
  100. Custom WP_List_Table displays blank rows
Categories admin Tags admin, hooks, login, wp-login-form
Create a a form for custom taxonomy terms
Create page options for theme?

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