WordPress:如何在登录页面上自定义"忘记密码"文本?

jas*_*tan 6 php wordpress function

我意识到这可能很简单,但我无法弄清楚如何更改WordPress登录页面上的"忘记密码"文本.

在登录页面上,有一个链接显示"忘记密码",我想将该文本更改为"获取新密码".我只是不确定用什么函数来覆盖子主题中的那个文本.

wordpress登录屏幕的屏幕截图

Sup*_*del 9

更改wordpress文本"忘记密码?"

function change_lost_your_password ($text) {

             if ($text == 'Lost your password?'){
                 $text = 'Forgot Password?';

             }
                    return $text;
             }
    add_filter( 'gettext', 'change_lost_your_password' );
Run Code Online (Sandbox Code Playgroud)


Ahm*_*ais 6

要更改此文本或与此相关的任何文本,您可以使用以下功能,它几乎与超级模特的答案相同,但已记录并验证了代码标准。

/**
 * Change some text.
 *
 * @param String $text WordPress Text Stream.
 * @return String
 */
function acme_change_some_text( $text ) {
    if ( 'Lost your password?' === $text ) {
        $text = 'Forgot Your Password?';
    }

    // Important to return the text stream.
    return $text;
}

// Hook this function up.
add_action( 'gettext','acme_change_some_text' );
Run Code Online (Sandbox Code Playgroud)

这是一个方便的 gif 来解释正在发生的事情。

动图


Iva*_*yev 2

该函数有几个参数可以更改默认设置。例如,您可以指定:表单及其元素的 ID 名称(用于 CSS 样式)、是否打印“记住我”复选框以及用户成功登录后重定向到的 URL(默认为保留在同一页面):

<?php
if ( ! is_user_logged_in() ) { // Display WordPress login form:
    $args = array(
        'redirect' => admin_url(), 
        'form_id' => 'loginform-custom',
        'label_username' => __( 'Username custom text' ),
        'label_password' => __( 'Password custom text' ),
        'label_remember' => __( 'Remember Me custom text' ),
        'label_log_in' => __( 'Log In custom text' ), //you can change here
        'remember' => true
    );
    wp_login_form( $args );
} else { // If logged in:
    wp_loginout( home_url() ); // Display "Log Out" link.
    echo " | ";
    wp_register('', ''); // Display "Site Admin" link.
}
?>
Run Code Online (Sandbox Code Playgroud)

该表单本身是由 WordPresswp-includes/general-template.php文件中的代码生成的。因为您的自定义登录页面与内置 WordPress 登录页面 (wp-login.php) 不同