STYLE SWITCHER

Displaying user role name in WordPress CMS

A simple method of showing user role in our CMS frontend
<?php
function get_user_role($user_id) {
                    global $wp_roles;
                   $roles = array();
                    $user = new WP_User( $user_id );
                    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
                    foreach ( $user->roles as $role )
                        $roles[] .= translate_user_role($wp_roles->roles[$role]['name']);
                    }
                    return implode(', ',$roles);
                }
?>
<?php echo get_user_role($user->ID); ?>

Recent Article

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Keep your skills sharp, get informed.

    Subscribe to our mailing list and get interesting stuff and updates to your email inbox