我试图显示自定义作者名称,而不是我使用WP_Members插件创建的。我在主题的function.php中使用了这个函数。
function get_author_role_name(){
$role = get_the_author_meta('roles')['0'];
echo esc_html($role);
}
它工作得很好,但是它显示了角色的"蛞蝓"。我要显示名字!
交货。名称:"我的自定义角色",显示为"My - Custom - Role"。
所以,我可以用空格"代替"-",我可以使用ucwords()函数,但是,有一个函数可以直接获得真实的名称吗?我找不到!
感谢EDIT - SOLUTION HERE:
function get_author_role_name(){
$get_role = get_the_author_meta('roles')['0'];
global $wp_roles;
$role = $wp_roles->roles[$get_role]['name'];
echo esc_html($role);
}
根据上面的链接,我编辑了我的函数:
function get_author_role_name(){
$get_role = get_the_author_meta('roles')['0'];
global $wp_roles;
$role = $wp_roles->roles[$get_role]['name'];
echo esc_html($role);
}