### [如何显示WordPress登录用户角色](https://www.prosaas.cn/article/9560) **Published:** 2019-11-23T03:13:13 **Author:** 5201314 **Excerpt:** 下面由WordPress入门教程栏目给大家分享一段WordPress显示登录用户角色的代码。将下面的代码添加到… 下面由**WordPress入门教程**栏目给大家分享一段WordPress显示登录用户角色的代码。 ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212132510366.jpg) 将下面的代码添加到当前主题functions.php中: function get\_user\_role() { global $current\_user; $user\_roles = $current\_user->roles; $user\_role = array\_shift($user\_roles); return $user\_role; } 在主题模板适当位置添加调用代码: 再配合以下的WordPress用户信息函数: 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 '用户 ID:' . $current\_user->ID . "\\n"; ?> WordPress用户信息调用基本算是全了。应该还差显示用户文章和评论数量,下次再写。 以上就是如何显示WordPress登录用户角色的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** php, WordPress **Categories:** WordPress ---