I am trying to populate the Current logged in user role name but it is showing slug of current user
I want to generate the user role name but not slug
function get_user_role() {
global $current_user;
$user_roles = $current_user->roles;
$user_role_name = array_shift($user_roles);
return $user_role_name;
}
add_shortcode('display_user_role', 'get_user_role');
You can use the global roles API to get the name of a role.
Something like this:
function get_user_role() {
global $wp_roles;
$user = wp_get_current_user();
if($user){
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
foreach ( $user->roles as $role )
echo $wp_roles->roles[$role]['name'];
}
}
}
add_shortcode('display_user_role', 'get_user_role');