在我的 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/