Skip to main content
translate_user_role doesn't work in the front-end currently. That's why i include it.
Source Link

You can get current user role name(translatable name but not slug) by following function, you just need to pass a parameter current user role slug nameas a parameter:

function wp_get_current_user_translatable_role_name( $current_user_role_slug = '' ) {
    $role_name = '';

    if ( ! function_exists( 'get_editable_roles' ) ) {
        require_once ABSPATH . 'wp-admin/includes/user.php';
    }

    // Please note that translate_user_role doesn't work in the front-end currently.
    load_textdomain( 'default', WP_LANG_DIR . '/admin-' . get_locale() . '.mo' );

    $editable_roles = array_reverse( get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role( $details['name'] );
        // preselect specified role
        if ( $current_user_role_slug == $role ) {
            $role_name  = $name;
        }
    }

    echo $role_name ;
}

Now, get current user role slug name by following code:

$user_meta = get_userdata(get_current_user_id());
$current_user_role_slug = $user_meta->roles[0];

Use wp_get_current_user_translatable_role_name( $current_user_role_slug ); function to get current user role name(translatable name but not slug).

NOTE: User must have to login to view role name.

You can get current user role name(translatable name but not slug) by following function, you just need to pass a parameter current user role slug name:

function wp_get_current_user_translatable_role_name( $current_user_role_slug = '' ) {
    $role_name = '';

    if ( ! function_exists( 'get_editable_roles' ) ) {
        require_once ABSPATH . 'wp-admin/includes/user.php';
    }

    $editable_roles = array_reverse( get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role( $details['name'] );
        // preselect specified role
        if ( $current_user_role_slug == $role ) {
            $role_name  = $name;
        }
    }

    echo $role_name ;
}

Now, get current user role slug name by following code:

$user_meta = get_userdata(get_current_user_id());
$current_user_role_slug = $user_meta->roles[0];

Use wp_get_current_user_translatable_role_name( $current_user_role_slug ); function to get current user role name(translatable name but not slug).

NOTE: User must have to login to view role name.

You can get current user role name(translatable name but not slug) by following function, you just need to pass current user role slug as a parameter:

function wp_get_current_user_translatable_role_name( $current_user_role_slug = '' ) {
    $role_name = '';

    if ( ! function_exists( 'get_editable_roles' ) ) {
        require_once ABSPATH . 'wp-admin/includes/user.php';
    }

    // Please note that translate_user_role doesn't work in the front-end currently.
    load_textdomain( 'default', WP_LANG_DIR . '/admin-' . get_locale() . '.mo' );

    $editable_roles = array_reverse( get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role( $details['name'] );
        // preselect specified role
        if ( $current_user_role_slug == $role ) {
            $role_name  = $name;
        }
    }

    echo $role_name ;
}

Now, get current user role slug name by following code:

$user_meta = get_userdata(get_current_user_id());
$current_user_role_slug = $user_meta->roles[0];

Use wp_get_current_user_translatable_role_name( $current_user_role_slug ); function to get current user role name(translatable name but not slug).

NOTE: User must have to login to view role name.

Misunderstanding the point of question but now understand the point and fix it as well :)
Source Link

You can get current user role name(translatable name but not slug) by following codefunction, you just need to pass a parameter current user role slug name:

function wp_get_current_user_translatable_role_name( $current_user_role_slug = '' ) {
    $role_name = '';

    if (is_user_logged_in ! function_exists( 'get_editable_roles' ) ) {
    $current_user    require_once ABSPATH . 'wp-admin/includes/user.php';
    }

    $editable_roles = wp_get_current_userarray_reverse( get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role( $details['name'] );
        // preselect specified role
        if ( $current_user_role_slug == $role ) {
            $role_name  = $current_user->roles[0];$name;
    return $role_name;   }
    }else{ 

    returnecho NULL;$role_name ;
}

Now, get current user role slug name by following code:

$user_meta = get_userdata(get_current_user_id());
$current_user_role_slug = $user_meta->roles[0];

Use $role_namewp_get_current_user_translatable_role_name( $current_user_role_slug ); variablefunction to get current user role name(translatable name but not slug).

NOTE: User must have to login to view role name otherwise this code will return NULL.

You can get current user role name by following code:

if(is_user_logged_in()){
    $current_user = wp_get_current_user();
    $role_name = $current_user->roles[0];
    return $role_name;
}else{
    return NULL;
}

Use $role_name variable to get current user role name.

NOTE: User must have to login to view role name otherwise this code will return NULL

You can get current user role name(translatable name but not slug) by following function, you just need to pass a parameter current user role slug name:

function wp_get_current_user_translatable_role_name( $current_user_role_slug = '' ) {
    $role_name = '';

    if ( ! function_exists( 'get_editable_roles' ) ) {
        require_once ABSPATH . 'wp-admin/includes/user.php';
    }

    $editable_roles = array_reverse( get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role( $details['name'] );
        // preselect specified role
        if ( $current_user_role_slug == $role ) {
            $role_name  = $name;
        }
    } 

    echo $role_name ;
}

Now, get current user role slug name by following code:

$user_meta = get_userdata(get_current_user_id());
$current_user_role_slug = $user_meta->roles[0];

Use wp_get_current_user_translatable_role_name( $current_user_role_slug ); function to get current user role name(translatable name but not slug).

NOTE: User must have to login to view role name.

Source Link

You can get current user role name by following code:

if(is_user_logged_in()){
    $current_user = wp_get_current_user();
    $role_name = $current_user->roles[0];
    return $role_name;
}else{
    return NULL;
}

Use $role_name variable to get current user role name.

NOTE: User must have to login to view role name otherwise this code will return NULL