javascript - WordPress : Change name in my button from 'LOGOUT' to the name of the user?

标签 javascript php html wordpress

在我的 WordPress 网站上,标题中有一个模式按钮,允许用户登录。登录后,按钮文本将从“登录”更改为“注销”,使用户能够根据需要注销。我怎样才能让该按钮显示用户名而不是“注销”。例如,我的名字是蒂娜,当我第一次选择登录按钮并成功登录时,标题显示“注销”,但我希望它显示“蒂娜”。感谢您提前的帮助!

HTML:

<?php if (is_user_logged_in()) { ?>
    <a class="login_button" href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>
<?php } else { ?>
    <a class="login_button" id="show_login" href="">Login</a>
<?php } ?>

<form id="login" action="login" method="post">
    <h1><img src="image.png" class="login-logo" width="80" height="auto"></h1>
    <p class="status"></p>
    <label for="username">Username</label>
    <input id="username" type="text" name="username">
    <label for="password">Password</label>
    <input id="password" type="password" name="password">
    <a class="lost" href="<?php echo wp_lostpassword_url(); ?>">Forgotten your password?<br><br></a>
    <input class="submit_button" type="submit" value="Login" name="submit">
    <a class="close" href=""><span class="glyphicon glyphicon-remove"></span></a>
    <?php wp_nonce_field( 'ajax-login-nonce', 'security' ); ?>
</form>

最佳答案

您可以使用wordpress提供的wp_get_current_user()内置函数,根据以下代码片段,函数将返回当前登录的用户信息对象:

<?php
    $current_user = wp_get_current_user();
    echo 'User first name:' . $current_user->user_firstname;
    echo 'User last name:' . $current_user->user_lastname;
?>

关于javascript - WordPress : Change name in my button from 'LOGOUT' to the name of the user?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36839329/

相关文章:

html - 如何在 Objective-C 中解析字符串

javascript - 将 mongodb 中嵌套数组中的日期转换为字符串

html - 如何在保持 DRY 的同时在多个 <td> 元素中应用 ng-if(或其他条件)

javascript - react : Invariant Violation: ReactMount: Two valid but unequal nodes with the same `data-reactid` : . 0.5

php - 通知 : Undefined index: variable

php - laravel - 查询生成器与 Eloquent

php - mysqli 访问被拒绝 (42000/1044) linux 权限?

html - 奇怪的 css 行为 - 图像内联不在下方

javascript - 如何检测TraceMonkey?

javascript - 如何配置 Webpack 5 包以使用全局 jQuery?