Here we will discuss about custom login functionality in Wordpress. Please follow the below example to build custom login functionality in Wordpress:
$userCredential = array();
$userCredential['user_login'] = $_POST['username']; //get your login form info submitted as user name
$userCredential['user_password'] = $_POST['password']; //get your login form info submitted as password
$userCredential['remember'] = true; // If you want to save data in cookies to remember this
$userStatus = wp_signon( $userCredential, false ); //wp_signon is a custom function for login functionality
if (is_wp_error($userStatus)){
echo $userStatus->get_error_message(); // if login fail it will display the error
}else{
wp_redirect('userprofile'); // after successful login page will redirect to userprofile page
}
0 Comment(s)