登录wordpress网站时如何显示用户的用户名? [英] how to show user's username when logged into a wordpress site?
本文介绍了登录wordpress网站时如何显示用户的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户登录到我的 wordpress 站点时,我希望我的站点的标题显示为登录为".
我不知道如何回显当前用户的用户名,这是我得到的代码...
<li><a href="#">以用户名登录</a></li><li><a href="#">注销</a></li>';} 别的 {echo '<li><a href="#">注册</a></li><li><a href="#">登录</a></li>
';}?>
我想替换用户名.
非常感谢任何帮助.
谢谢,
标记
解决方案
你可以使用 get_currentuserinfo() 获取任何登录用户信息的函数..
user_login ."\n";echo '用户邮箱:'.$current_user->user_email ."\n";echo '用户名:'.$current_user->user_firstname ."\n";echo '用户姓氏:'.$current_user->user_lastname ."\n";echo '用户显示名称:'.$current_user->display_name ."\n";echo '用户名:'.$current_user->ID ."\n";?>
在你的情况下可能是
<li><a href="#">以.$current_user->display_name."的身份登录.</a></li><li><a href="#">注销</a></li>';} 别的 {echo '<li><a href="#">注册</a></li><li><a href="#">登录</a></li>
';}?>
:)
I would like to have the header of my site reading "Logged in as " when a user is logged into my wordpress site.
I dont know how to echo the username of the current user, heres the code I'm got...
<?php
if ( is_user_logged_in() ) {
echo '<ul id="mem" class="clearfix">
<li><a href="#">Logged in as Username</a></li>
<li><a href="#">Logout</a></li>
</ul>';
} else {
echo '<ul id="mem" class="clearfix">
<li><a href="#">Register</a></li>
<li><a href="#">Login</a></li>
</ul>';
}
?>
and I'd like to replace Username.
Any help is much appreciated.
Thanks,
Mark
解决方案
you can use get_currentuserinfo() function to grab any logged in users info..
<?php global $current_user;
get_currentuserinfo();
echo 'Username: ' . $current_user->user_login . "\n";
echo 'User email: ' . $current_user->user_email . "\n";
echo 'User first name: ' . $current_user->user_firstname . "\n";
echo 'User last name: ' . $current_user->user_lastname . "\n";
echo 'User display name: ' . $current_user->display_name . "\n";
echo 'User ID: ' . $current_user->ID . "\n";
?>
in your case it could be
<?php
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo '<ul id="mem" class="clearfix">
<li><a href="#">Logged in as '.$current_user->display_name.'</a></li>
<li><a href="#">Logout</a></li>
</ul>';
} else {
echo '<ul id="mem" class="clearfix">
<li><a href="#">Register</a></li>
<li><a href="#">Login</a></li>
</ul>';
}
?>
:)
这篇关于登录wordpress网站时如何显示用户的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文