📣 Our next Live Stream Event is taking place on July 18, 2025

Display The Current User’s Role Anywhere In WordPress Using This Code Snippet

It is very simple to add the current user’s role title in WordPress to any post or page using a small and easy-to-follow code snippet.

Using this code snippet you can customise any area of your LearnDash LMS environment, such as we did for one of our recent client custom-built platforms by including the user role title as part of the LearnDash LMS profile widget area.

The code snippet to apply within your page template PHP file is as follows:

<?php
global $current_user;
$role = $current_user->roles[0];
$role_name = $role ? wp_roles()->get_names()[ $role ] : '';
echo $role_name;
?>

We applied this code snippet ourselves to the profile.php file found in the LearnDash Templates folder, just move this over to the ld30/shortcodes template override folder in your child theme.

Take a look at the result below:

LearnDash Profile Widget Customisation

The great thing about this code snippet is that it returns the user role title even if this has been customised in some way, such as via the popular free User Role Editor plugin for WordPress.

For more great idea for how you can customise LearnDash LMS to meet your organisations needs, check out our blog post series covering more great tips and tutorials for LearnDash LMS.

You can also feel free to contact Discover eLearning at any time to discuss any custom development needs for your own bespoke Learning Management System.

Schedule a meeting

Why not book a consultation call with us? We’re here to assist you with any questions or concerns you may have.

Please note: All bookings are subject to confirmation. We reserve the right to reschedule based on availability.