0
我試圖顯示自定義作者名稱比我用WP_Members插件創建。我在我的主題的function.php中使用了這個函數。WordPress的 - 顯示「自定義作者角色名稱」 - WP成員插件安裝
function get_author_role_name(){
$role = get_the_author_meta('roles')['0'];
echo esc_html($role);
}
它工作正常,但它顯示角色的「slug」。我想顯示這個名字!
Ex。名稱:「我的自定義角色」,該功能顯示「我的自定義角色」。所以,我可以用空格替換「 - 」,我可以使用ucwords()函數,但是,是否有函數直接獲取真實姓名?我找不到它!
感謝
編輯 - 這裏的解決方案:
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);
}