0
votes

Expectation:
I want to hide the login message that shows up on the Wordpress login form after a user has logged out. Added screenshot of the message that I am trying to hide.

https://i.imgur.com/vJm56sI

Wordpress Version 5.4.2

Wordpres theme: Oceanwp 1.8.9

I have used the below mentioned code in the functions.php file of my theme.

add_filter( 'wp_login_errors', 'my_logout_message' );

function my_logout_message( $errors ){

    if ( isset( $errors->errors['loggedout'] ) ){
        return null;
    }

    return $errors;
}

Error Recieved:

I have provided the screen shot of the error that I have recieved.

https://i.imgur.com/xlpGiwM.png

Also, the login form isn't visible after user logout.

1
You probably want to unset $errors->errors['loggedout'] not return null by returning null you are removing the entire $errors object from the response which causes this error when later code that expects it to be there tries to call methods on it - Wesley Smith

1 Answers

3
votes

Yes hii interesting, perhaps it might be useful to override the error ID loggedout:

add_filter('wp_login_errors', 'my_logout_message');

function my_logout_message($errors) {
    // Remove the message

    $errors->remove('loggedout');

    // Or customize the message:

    if (array_key_exists('loggedout', $errors->errors)) {
        $errors->errors['loggedout'][0] = 'My message';
    }

    return $errors;
}