Skip to main content

This article introduces a function that we can include in our WordPress site’s Child Theme in order to override the default name used in the LearnDash Focus Mode welcome message.

Users of LearnDash’s Focus Mode (introduced with LearnDash version 3.0) will be familiar with the welcome message that is shown to any user accessing either a lesson or topic page.

The default behaviour of LearnDash is to display the user’s Username in that message, e.g Hello, ##USERNAME##!

This may not be ideal however for learning platform admins where perhaps the username is automatically generated to be a mixture of names with no spaces, or perhaps a username that the user sets themselves during checkout/registration which may not look as professional as we would like in LearnDash.

Thankfully we can easily override this behaviour with a small piece of code placed in our Child Theme’s functions.php file. This code is provided by LearnDash themselves (to replace with First Name only), but I have adapted the code so that if a Last Name is present it will display First+Last name. If no last name is found then it will just display the First Name, and if there is no first name then it will go back to the default display name for that user:

add_filter( 'ld_focus_mode_welcome_name', function( $display_name, $user_info ) {
if ( $user_info->first_name ) {

if ( $user_info->last_name ) {
return $user_info->first_name . ' ' . $user_info->last_name;
}

return $user_info->first_name;
}

return $user_info->display_name;
}, 20, 2);

 

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.

6 Comments

  • Molly says:

    Hi Chris
    Thanks for this helpful post!
    But: I need only the first name in this section without last name. Can you help me with a code? I’m not very good with codes… 🙂

    Thanks a lot!
    Molly

    • Chris Hodgson says:

      Hi Molly,

      Sure! That can easily be done. Use this instead:

      add_filter( ‘ld_focus_mode_welcome_name’, function( $display_name, $user_info ) {
      if ( $user_info->first_name ) {

      return $user_info->first_name;
      }

      return $user_info->display_name;
      }, 20, 2);

      • Molly says:

        Thanks Chris
        Unfortunately I have this error:
        Warning: Use of undefined constant ‘ld_focus_mode_welcome_name’ – assumed ‘‘ld_focus_mode_welcome_name’’
        Any idea?
        thx
        Molly

        • Chris Hodgson says:

          Argh I think my website has reformatted the comment so the quotation marks are changed to a ‘curly’ typographic style, so if you try to copy/paste my comment directly into your site’s code it isn’t going to work!

          Please instead copy my original code from the post above, and delete the following lines:

          if ( $user_info->last_name ) {
          return $user_info->first_name . ‘ ‘ . $user_info->last_name;
          }

Leave a Reply

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