admin管理员组文章数量:1313385
I would like to display a nickname instead of username/display name on top of my website. I want to insert PHP codes which can display that Nickname in a PHP page. I have tried these codes below, but they don't work:
........some codes above...................
<?php global $current_user; wp_get_current_user(); ?>
{if is_user_logged_in()}
<?php
$nickname = $current_user->user_nickName;
?>
<?php echo $nickname; ?>
..........some codes below.........
But it works for username as below:
........some codes above...................
<?php global $current_user; wp_get_current_user(); ?>
{if is_user_logged_in()}
<?php
$username = $current_user->user_login;
?>
<?php echo $username; ?>
..........some codes below.........
Any suggestion is very appreciated!
I would like to display a nickname instead of username/display name on top of my website. I want to insert PHP codes which can display that Nickname in a PHP page. I have tried these codes below, but they don't work:
........some codes above...................
<?php global $current_user; wp_get_current_user(); ?>
{if is_user_logged_in()}
<?php
$nickname = $current_user->user_nickName;
?>
<?php echo $nickname; ?>
..........some codes below.........
But it works for username as below:
........some codes above...................
<?php global $current_user; wp_get_current_user(); ?>
{if is_user_logged_in()}
<?php
$username = $current_user->user_login;
?>
<?php echo $username; ?>
..........some codes below.........
Any suggestion is very appreciated!
Share Improve this question edited Oct 13, 2020 at 13:34 Jesse Nickles 7357 silver badges19 bronze badges asked Apr 29, 2018 at 17:34 daro2013daro2013 251 silver badge6 bronze badges 2- edit your question to explain how you create the nickname. – mmm Commented Apr 29, 2018 at 17:57
- The user nickname is part of core WP. – Nathan Johnson Commented Apr 29, 2018 at 17:58
1 Answer
Reset to default 3Because the $current_user
object doesn't have a property called user_nickName
because the user nickname is stored in the user meta.
$user = wp_get_current_user();
$meta = get_user_meta( $user->ID );
$nickname = $meta->nickname;
Or
$nickname = get_user_meta( wp_get_current_user()->ID, 'nickname', true );
本文标签: How to display user nickname (not display name) in PHP template
版权声明:本文标题:How to display user nickname (not display name) in PHP template? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741919974a2404953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论