How to Change the Logout Message in WordPress?

I would like to change the message “You are now logged out.”, when the user logs out.
Is there any hook that I can use to modify it?

I’ve tried using login_message or login_error filter but does not work.
I don’t want to modify wp-login.php.

Related posts

Leave a Reply

3 comments

  1. You need to add this code in your functions.php

    add_filter( 'login_message', 'so_13641385_custom_logout_message' );
    add_action( 'login_head','so_13641385_custom_login_head' );
    
    // Detect logout or login, and display correspondent message
    function so_13641385_custom_logout_message() 
    {
        //check to see if it's the logout screen
        if ( isset($_GET['loggedout']) && TRUE == $_GET['loggedout'] ) 
            $message = "<p class='custom-message'>Custom logged out Message.</p><br />";
    
        //they are logged in
        else 
            $message = "<p class='custom-message'>Custom Login Message.</p><br />";
    
        return $message;
    } 
    
    //outputs the CSS needed to blend custom-message with the normal message
    function so_13641385_custom_login_head() 
    {
        ?>
        <style type="text/css">
        #login_error, .message { display:none; }
        .custom-message {
            -moz-border-radius:3px 3px 3px 3px;
             border-style:solid;
             border-width:1px;
             margin:0 0 16px 8px;
             padding:12px;
        }
        .login .custom-message {
            background-color:#FFFFE0;
            border-color:#E6DB55;
        }
        </style>
        <?php
    }
    

    Replace custom message with your message

  2. Use filter login_messages not login_message

    function custom_logout_message(){
      return 'You are not login!';
    }
    add_filter( 'login_messages', 'custom_logout_message' );
    
  3. Improving on brasofilo’s answer:

    1. The question does not ask for a log-in message. Provision of such is superfluous.
    2. It’s superior to use the existing message class rather than defining a custom class and trying to transpose CSS styling.
    3. It’s best to use filters when they are available.

    Code:

    add_filter( 'wp_login_errors', 'my_logout_message' );
    
    function my_logout_message( $errors ){
    
        if ( isset( $errors->errors['loggedout'] ) ){
            $errors->errors['loggedout'][0] = 'Custom Logged-Out Message.';
        }
    
        return $errors;
    }