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. Customize WordPress Password-Reset Behavior
  5. How to change user password with wp-cli?
  6. Loosen/disable password policy
  7. Password Protect Custom Page
  8. Password protecting a page
  9. How to save Admin FTP password
  10. How can I change the default wordpress password hashing system to something custom?
  11. If I change the salt keys in my wp-config will all passwords break?
  12. Conditional to test if post has password protection enabled
  13. Bypass password protected posts via GET variable
  14. Check the password of a user
  15. How to add Wp_error using lostpassword_post hook when validating custom field?
  16. Create a USERNAME and PASSWORD protected WordPress page
  17. Why do generated passwords start/end with spaces?
  18. Duplicate hash method for password in .NET
  19. How can I modify the default reset (lost) password email text?
  20. Hide password protected posts
  21. Safe to store SMTP password in wp-config.php?
  22. Access code/password only restricts page access, no user registration..?
  23. PasswordHash not found in namespace
  24. Force all users in MU to change their passwords
  25. How to customise wp-login.php only for users who are setting a password for the first time?
  26. Reseting admin password through PHPMyadmin fails
  27. Check Password Reset Key Not Woking
  28. Reset password – set minimum length for new password
  29. How to shorten length of auto generated password sent during registration?
  30. Forgot password not working
  31. wp_hash_password unexpected behaviour
  32. Password reset message – change the network_home_url( ‘/’ )
  33. Redirect a password protected page?
  34. Lost password link is redirecting to /shop/my-account/lost-password/
  35. WordPress: force users to change password on first login
  36. Can’t login to wordpress despite changing password to something known directly in MySQL or using “Password Reset by Email” feature
  37. Change default recovery link expiration time
  38. Remove lost password form and URL
  39. Lost password link redirects to my-account/lost-password/,how to fix it back to default lost password
  40. Password protect custom template
  41. Set content type to HTML for lost password email only
  42. Custom password generator for users
  43. Where is the reset password key stored/generated?
  44. Enqueue style for Password Reset page
  45. Password protecting template, secured content not showing if even password is right
  46. How validate usernames/passwords against WP’s database?
  47. Make post password required to publish
  48. WordPress reset password returns invalid key
  49. Add error message on password protected pages
  50. User password field is empty
  51. Password reset bug? – “Sorry, that key does not appear to be valid”
  52. How to set minimum length and error message for password recovery?
  53. Why is resetting the WordPress Users password not working?
  54. Get plain password on register
  55. post_password_required() not recognizing cookie set with correct password
  56. How Authentication in wordpress works? wp_authenticate_username_password()
  57. Password protect the site (without htaccess or membership)
  58. Password Protected page not asking for a password
  59. I would like to password protect my entire WordPress site (ip validated), except for one page
  60. Password protection for page template
  61. reset password link redirect to login page
  62. Password reset – Disabled for LDAP accounts
  63. how to remotely check a username / password from within a plugin
  64. Password changed [duplicate]
  65. Enable Update button only when password is shown strong
  66. Use Password Protected Form without the use of wp-login.php
  67. How to get user password before being encrypted outside the wordpress core once add a new user from dashboard?
  68. Adding parameters to password reset key
  69. wp_hash_password create a different hash everytime
  70. Custom password form allows unlock two posts with the same password
  71. How to change password
  72. Generating the password reset link automatically
  73. Password protect pages – allow more than one password
  74. Deep customization of wp-login.php
  75. password recovery key is invalid on custom reset
  76. Like to store multiple passwords in db table wp_posts field post_password?
  77. Password Protected Post is invisible until you login
  78. Send password to user instead of reset password link
  79. Protect Passwords in wp_users with stronger protection than MD5
  80. Custom form for password protected page
  81. How secure is a wp-config file?
  82. How to check user’s password?
  83. How to Remove or Deactivate “Application Passwords” in WordPress
  84. What’s the algorithm to verify user password?
  85. Where is the email content for retrieve_password_message stored?
  86. How to change “Reset Password” text on submit button
  87. Customize retrieve password message
  88. What is the CODEX intercept for wp-login.php?action=lostpassword
  89. How to recover password from a user
  90. Is there anyway to get the inputted password string from the login form?
  91. resend user login & password with custom button
  92. WordPress admin creation through phpmyadmin not working
  93. How to show my wordpress admin username & password?
  94. Why does hashing a password result in different hashes, each time?
  95. How do I create a function that modifies a message in the wp-login.php file?
  96. Can’t alter $lostpassword_url
  97. current user’s password check
  98. wordpress login without password just email address (NO 2 factor authentication with email)
  99. How to initiate password reset flow by code
  100. Change password fields
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
  • 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