简体   繁体   中英

Display user role in comments wordpress

So as my name suggests I am a complete newb. I want to create new user roles, assign them to some users and display user role in comments beside the username with normal subscriber not having any role shown.

I did see a thread regarding it In wordpress How to display USER ROLE in comments

Being a complete newb I did not know where to paste the code posted in comments and whether to use the code submitted by the thread starter.

Please help, thanks

Hope this will help for you to display the role of the logged users.

global $wp_roles;
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift($roles);

This works for me.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM