如何更改WordPress中的注销消息?

问题描述 投票:1回答:3

当用户退出时,我想更改“您现在已退出。”消息。 有没有可以用来修改它的钩子?

我尝试过使用login_messagelogin_error过滤器,但不起作用。 我不想修改wp-login.php

wordpress
3个回答
1
投票

您需要在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
}

用您的消息替换自定义消息


0
投票

改进brasofilo的答案:

  1. 问题不是要求登录消息。提供此类服务是多余的。
  2. 它优于使用现有的消息类,而不是定义自定义类并尝试转置CSS样式。
  3. 最好在过滤器可用时使用它们。

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;
}

0
投票

使用过滤器login_messages而不是login_message

function custom_logout_message(){
  return 'You are not login!';
}
add_filter( 'login_messages', 'custom_logout_message' );
© www.soinside.com 2019 - 2024. All rights reserved.