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);