Processing login error on a custom page template

I am trying to create a very simple WordPress plugin to display and process the WordPress login form. The plugin should display a login form on a custom page template and display login error on that page in case if it fails.

The problem is that I am unable to retrieve the error, it shows empty. Here is what I am trying:

//display login form

function my_login_form(){

if ( is_wp_error( $login_err ) ) { //always empty
$error_string = $login_err -> get_error_message();

$args = array(
‘redirect’ => home_url(),
‘id_username’ => ‘user’,
‘id_password’ => ‘pass’,

wp_login_form( $args );


//process login

add_filter(‘authenticate’, ‘check_login_submit’, 40, 3);

function check_login_submit($user, $username, $password) {

if ( $user == null ) {
$login_err = new WP_Error();
$login_err = new WP_Error(‘authentication_failed’, __(‘ERROR: Invalid username or incorrect password.’));

return $WP_Error;

How can I retrieve and display $login_err?

Read more here:: Processing login error on a custom page template

Leave a Reply

Your email address will not be published. Required fields are marked *