add_shortcode('user_role', function() { global $wp_roles; if( is_user_logged_in() ) { $user = wp_get_current_user(); $roles = ( array ) $user->roles; echo '<span>'; foreach( $roles as $role ){ echo $wp_roles->roles[ $role ]['name'] ; } } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter