[Membership 2 Pro] Membership 2 user name

On a standard wordpress page I would like to say "Hello XXX", where "XXX" is the members first name.
Can I do this?
Geoff

  • Ash

    Hello Geoff

    Please use the following code:

    add_shortcode( 'welcome_user', function() {
    	if( ! is_user_logged_in() ) return;
    
    	$user = wp_get_current_user();
    	return 'Hello ' . $user->user_login;
    } );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Now, in any page or post, use the following shortcode:

    [welcome_user]

    It should show: Hello USERNAME

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash