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:
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.