Skip to main content

Looking to take a custom meta value from your user’s profile area in WordPress to display somewhere on your WordPress or LearnDash-based platform? Then the get_user_meta function provided by WordPress could provide to you the solution that you need!

The purpose of this function is to retrieve user meta field for a user, so in order to display custom meta values about any of your site’s users, such as on the learner or customer profile page of your platform, it is fairly simple to use.

The function itself accepts three separate argument values:

  • First is the user ID, which in order to pass in the current user ID value we can instead use another function available through WordPress – get_current_user_id()
  • Second is the meta key value. So whether the meta value you are wanting to display is created by a third-party plugin, or has been manually created by yourself (e.g. at user account registration) you will want to make of what that key value is.
  • And lastly is a boolean value called Single, which we would assign either true or false depending on whether we are intending for the returned value to be a single item and not, for example, an array of items.

Let’s now take a look at a practical use for this function!

In our example we will propose that we want to include some additional information about our user when they are viewing their LearnDash LMS user profile page. To achieve this we can apply our custom code snippet 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 in order to change the default behaviour of this widget.

The code we will use might look like the following:

<div class="profile-statement"><?php echo get_user_meta( get_current_user_id(), 'personal_statement', true ); ?></div>

In this case we have take a custom meta value stored against the key named personal_statement and placed the contents of that stored value onto the page within a div with the class “profile-statement”. This allows us to customise the style and positioning of that piece of dynamic content relative to wherever it has been placed in relation to any of the other profile widget elements.

Of course if you wish to use the dynamic Personal Statement meta value grabber that you have just created in more areas of your WordPress platform than just the LearnDash LMS profile widget then you could potentially register a new shortcode and use this to add the value to any page you wish from the WP-Admin edit post/page view.

We will discuss more about what is possible using this particular WordPress function in a future post!

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