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

Custom login form for front-end user as well as admin

Why in the first place you created custom tables? There is wp_usermeta table for storing any kind of extra data to build custom user profiles with extra fields.

Also you can hook into native WP login process and allow logging in with email.

What method of logging in you are using?

Checking if user is administrator:

if ( current_user_can( 'manage_options' ) ) {
/* A user with admin privileges */
    wp_redirect( 'YOUR_TARGET_ABSOLUTE_URL' );
    exit;
}

But there’s even better way, as described in Codex:

function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
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
        return $redirect_to;
    } else {
        return home_url();
    }
} else {
    return $redirect_to;
}
}

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

The function is pretty self explanatory. Change $redirect_to destination to one of your choice.

Related Posts:

  1. wordpress redirect after password reset
  2. Can I use core passworded page/post functions outside of wp-login.php?
  3. How to Disable Pre-population of Password on Password Reset
  4. How to change user password with wp-cli?
  5. Loosen/disable password policy
  6. Password Protect Custom Page
  7. Password protecting a page
  8. How to save Admin FTP password
  9. If I change the salt keys in my wp-config will all passwords break?
  10. Conditional to test if post has password protection enabled
  11. How to add Wp_error using lostpassword_post hook when validating custom field?
  12. Duplicate hash method for password in .NET
  13. Hide password protected posts
  14. Access code/password only restricts page access, no user registration..?
  15. PasswordHash not found in namespace
  16. Force all users in MU to change their passwords
  17. How to customise wp-login.php only for users who are setting a password for the first time?
  18. Reseting admin password through PHPMyadmin fails
  19. Check Password Reset Key Not Woking
  20. Reset password – set minimum length for new password
  21. How to shorten length of auto generated password sent during registration?
  22. wp_hash_password unexpected behaviour
  23. Lost password link is redirecting to /shop/my-account/lost-password/
  24. Change default recovery link expiration time
  25. Set content type to HTML for lost password email only
  26. Enqueue style for Password Reset page
  27. Password protecting template, secured content not showing if even password is right
  28. Make post password required to publish
  29. Add error message on password protected pages
  30. User password field is empty
  31. Get plain password on register
  32. post_password_required() not recognizing cookie set with correct password
  33. How Authentication in wordpress works? wp_authenticate_username_password()
  34. Password protect the site (without htaccess or membership)
  35. Password Protected page not asking for a password
  36. I would like to password protect my entire WordPress site (ip validated), except for one page
  37. how to remotely check a username / password from within a plugin
  38. Password changed [duplicate]
  39. Enable Update button only when password is shown strong
  40. Use Password Protected Form without the use of wp-login.php
  41. How to get user password before being encrypted outside the wordpress core once add a new user from dashboard?
  42. wp_hash_password create a different hash everytime
  43. How to change password
  44. Generating the password reset link automatically
  45. Password protect pages – allow more than one password
  46. password recovery key is invalid on custom reset
  47. Like to store multiple passwords in db table wp_posts field post_password?
  48. Send password to user instead of reset password link
  49. Custom form for password protected page
  50. How to check user’s password?
  51. What’s the algorithm to verify user password?
  52. Where is the email content for retrieve_password_message stored?
  53. Customize retrieve password message
  54. What is the CODEX intercept for wp-login.php?action=lostpassword
  55. How to recover password from a user
  56. WordPress admin creation through phpmyadmin not working
  57. Can’t alter $lostpassword_url
  58. current user’s password check
  59. wordpress login without password just email address (NO 2 factor authentication with email)
  60. How to initiate password reset flow by code
  61. Change password fields
  62. lostpassword_redirect filter is not used
  63. Requiring wp-login.php sends headers automatically
  64. Password Protect or IP to access under development WordPress site otherwise shown a placeholder page
  65. Password-protected page redirecting to frontpage when I enter the password
  66. Temporally disable password to login with empty password?
  67. 2 accounts under same email preventing me from loging in
  68. wordpress custom password change problem
  69. Allow all reset password links within the past 24 hours to be valid and accepted
  70. Set id and password for each post
  71. I have to reset the admin password each time
  72. When I enter password, I’m redirected to the WordPress login form
  73. Create Member who can’t be changed
  74. wp_set_password() does not work!
  75. Automatically change the page password for more than one page
  76. Sending Reset Password email via Web API
  77. I can’t recover my password
  78. $expiration_duration = apply_filters( ‘password_reset_expiration’, DAY_IN_SECONDS );
  79. Cannot get function.php code to work to remove Lost Password link on live site
  80. Entering a WP site with a SMS code
  81. Problem with login / reset password links in users emails
  82. Lost Password redirect to My Account
  83. Multiple pages protected by different passwords. Possible to track multiple passwords at a time?
  84. How do I display the password field on the WordPress user registration screen?
  85. Not able to log for the first time on a salted WordPress by creating pwd on BD
  86. Custom page password recovery
  87. Password Protected Logout Button Not Working
  88. Is it possible to display newly generated password after wp_generate_password()?
  89. Password protect wp-login.php
  90. How do I password protect a page of posts on WordPress?
  91. Revise my keyword but still cannot login
  92. WordPress not taking password and username
  93. Is it possible to have users register without having a password?
  94. Password Protection for posts and pages [duplicate]
  95. How WordPress hashes passwords
  96. Reset Password – change from name and email address. It stucks at admin. Want to change it to info
  97. check if post is set to “password protected”
  98. Why can’t I create an Application Password?
  99. ‘random_password’ filters not taking effect
  100. Bypass a WordPress Password Protected Page via url
Categories password Tags password, wp-login-form
Email Post Attachment on wp_insert_post Action
Change name of existing post status type

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