php - Wordpress - Display "Custom Author Role Name" - WP Members Plugin Installed -


this question has answer here:

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -