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. WordPress – Security Question at Login from User’s Meta Data
  70. Does wp_login hook fire on user registration?
  71. Filtered dropdown for author?
  72. Add custom css class to wp-list-table row for custom post type
  73. Custom column with post ID not working in CPT
  74. Change order of the block editor’s panel
  75. How to enforce authentication for all resources?
  76. Mixed language in admin backend
  77. What Role to assign remote site developer?
  78. Add a user to edit the layout of a site
  79. Login form- no feedback
  80. How to authenticate/verify login credentials & check for user meta without logging in?
  81. CSS Styles specific to Admin Sidebar not loading
  82. 500 error for regular users, not for admin
  83. Display admin sidebar into custom post pages if logged
  84. Display notice in block editor after wp_insert_post_data hook
  85. Changing login url
  86. Modify ‘the_content’ appearance in the admin area
  87. Change password reqts with NO plugin without breaking resetpass link?
  88. Remove login link from Reset Password-screen
  89. Why am I not able to login to the admin
  90. WordPress site down for my IP only after trying to implement .htaccess whitelist
  91. WordPress site shows a white page for site/wp_admin. A login returns again to the login screen
  92. I accidentally rejected my wordpress admin account!
  93. Unknown phantom user “wordpress” created with admin privileges
  94. Is there a way to assign a default Category to a Post when the user creates a new Post?
  95. wp_login_form display no styled form
  96. Hide Dashboard and Profile from non admin in sidebar
  97. Redirecting after login except for a specific page
  98. What triggers WordPress automatic updates? (revisited)
  99. Replace Header Element on WordPress Login Page
  100. How to modify username before logging in?
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
  • 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