Skip to main content

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:

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.

Chris Hodgson

Chris Hodgson is an award-winning Digital learning Solutions Developer and Director of Discover eLearning Ltd. He supports organisations of all sizes to implement engaging, meaningful, and impactful eLearning solutions. Chris has 15 years’ experience working in both private and public sector learning and development.

Leave a Reply

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