php - Wordpress - Display "Custom Author Role Name" - WP Members Plugin Installed -
this question has answer here:
- wordpress role display name 3 answers
i tried display custom author name created wp_members plugin. used function inside function.php of theme.
function get_author_role_name(){ $role = get_the_author_meta('roles')['0']; echo esc_html($role); }
it works fine, displays "slug" of role. display name!
ex. name: "my custom role", function displays "my-custom-role".
so, replace "-" space " " , use ucwords() function, but, there function real name directly? can't find it!
thanks
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); }
based on above link, edited function so:
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); }
Comments
Post a Comment