
Using a WordPress Function to Create Custom Login Form
- December 22, 2016
- Leave a comment
In WordPress, you can access the default login page by redirecting to site_url/wp-admin OR site_url/wp-login.php. Additionally, WordPress allows you to create a custom login form at the front-end (either in a widget, pop-up or sidebar, etc.) of your website. This article will help you to create a custom login form by using a wp() function.
To achieve this functionality, WordPress provides you a wp_signon( $credentials, $secure_cookie ) function. This function uses the username, password and remember me as parameters. Using these credentials, this function will create a user session on the website.
If the given credentials are invalid, then it will return an error object holding the produced error or else it will return the user object on success.
1 2 3 4 5 6 7 8 9 10 11 |
$creds = array(); $creds['user_login'] = 'example'; $creds['user_password'] = 'plaintextpw'; $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) { echo $user->get_error_message(); } |
And you are done!
Where to put this code in to get a custom login page ?
Hi Chris,
Kindly place that piece of code in child’s theme Functions.php file with your credentials.
Once you enter your credential and get logged in, it won’t ask again about your credentials.
Regards,
—
Azeem | Client Service Executive
Email: support@presstigers.com