How to hide “You are now logged out” message on WordPress login form?

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The cause of your error is that the filter receives and is expected to return a WP_Error object, null is not an error object.

We can confirm this via the docs, and enforce it via type hinting:

function my_logout_message( WP_Error $error ) : WP_Error {

Additionally, if your code had worked, all errors would be eliminated, not just the logout message. There would be no way to tell a user their password was incorrect, that a password reset email or a confirmation email was on its way, etc

With this in mind, the WP_Error say there is a remove method, so we can remove the loggedout error if it’s present:

$error->remove( 'loggedout' );

I do not recommend this though


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x