functions – How to make my logged-in user-role shortcode displaying name instead of slug?

Question

I am trying to get my frontend to show the role of a logged-in user via Shortcode. I have the Shortcode functional (see below) but it displays the slug and not the real name in the frontend. This is a problem as the slugs are case insensitive and do not display any special characters. How do i get it to display the name rather than the slug?

Any help is greatly appreciated.

// [current_user_role]
function get_user_role() {
    global $current_user;
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    return $user_role;
}
add_shortcode('current_user_role', 'get_user_role');

0
PhpDoe 2 months 2023-10-01T13:32:00-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse