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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -