我正在创建Wordpress主题, 但无法获取当前用户名。我尝试了get_currentuserinfo(), 但似乎无法正常工作。是否有任何可用的功能来获取我可以在header.php模板文件中使用的用户名?
#1
你是否阅读了文档, 此示例对我来说效果很好:
<?php
global $current_user;
get_currentuserinfo();
echo $current_user->user_login;
?>
#2
它对我很好:
<?php
echo wp_get_current_user()->data->user_nicename;
?>
你可以访问而不是nicename的其他信息:

来源:
https://www.srcmini02.com/62565.html