获取 WordPress 主题中的当前用户名 (3.2)

发布于 2024-12-03 19:13:24 字数 140 浏览 3 评论 0原文

我正在创建 WordPress 主题,但无法获取当前用户名。我尝试了 get_currentuserinfo() 但它似乎不起作用。是否有任何工作函数可以获取我可以在 header.php 模板文件中使用的用户名?

I'm creating a WordPress theme, but I can't get the current username. I tried get_currentuserinfo() but it doesn't seem to work. Is there any working function to get the username that I can use in the header.php template file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

数理化全能战士 2024-12-10 19:13:24

您是否阅读了文档,这个示例对我来说效果很好:

<?php 
  global $current_user;
  wp_get_current_user() ;
  echo $current_user->user_login;
?>

Did you read the documentation, this example work well for me :

<?php 
  global $current_user;
  wp_get_current_user() ;
  echo $current_user->user_login;
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文