doujupa7567 2016-04-25 11:31
浏览 85
已采纳

WordPress:将我的按钮中的名称从“LOGOUT”更改为用户名?

On my WordPress site I have a modal button in the header that allows users to login. Once logged in the button text changes from 'LOGIN' to 'LOGOUT', giving the user the ability to logout if they want to. How can I get that button to show the users name instead of 'LOGOUT'. For example my name is Tina and when I first select the login button & login successfully the header shows 'LOGOUT' but I want it to show 'TINA' instead. Thanks for the help in advance!

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>
  • 写回答

2条回答 默认 最新

  • dougu2006 2016-04-25 11:42
    关注

    You can use wp_get_current_user() built-in function provided by wordpress, as per the following code-snippet, function will return the current logged in user information object:

    <?php
        $current_user = wp_get_current_user();
        echo 'User first name:' . $current_user->user_firstname;
        echo 'User last name:' . $current_user->user_lastname;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。