How to use <?php get_user_field(); ?>

I tried to use the following shortcode in php template (in child theme)
but it does not work, how is it?
<?php
$user_login = get_user_field(‘user_login’); # Username for the current User.
$user_email = get_user_field(‘user_email’); # Email Address for the current User.
$first_name = get_user_field(‘first_name’); # First Name for the current User.
$last_name = get_user_field(‘last_name’); # Last Name for the current User.
$full_name = get_user_field(‘full_name’); # First and Last Name for the current User.
$display_name = get_user_field(‘display_name’); # Display Name for the current User.
$avatar = get_user_field(‘avatar’, 0, array(‘size’ => 96)); # Avatar tag.
$s2member_custom = get_user_field(‘s2member_custom’);
?>

What do you mean by “it doesn’t work.” All your code does is create variables. What do you want it to do?

I want to display member name automatically,
when in wordpress editor I can use “[s2Get user_field=“display_name” /]” so it can bring the name of the member who login.
but when I use “<?php
$display_name = get_user_field(‘display_name’);
?>” in the custom php page theme it does not show the name of the member login

As I said, you are just creating variables. You need to echo the values if you want them to show on the page, like this:

<?php
echo get_user_field( 'user_login' ); # Username for the current User.
echo get_user_field( 'user_email' ); # Email Address for the current User.
echo get_user_field( 'first_name' ); # First Name for the current User.
echo get_user_field( 'last_name' ); # Last Name for the current User.
echo get_user_field( 'full_name '); # First and Last Name for the current User.
echo get_user_field( 'display_name' ); # Display Name for the current User.
echo get_user_field( 'avatar', 0, array( 'size' => 96 ) ); # Avatar tag.
echo get_user_field( 's2member_custom' );
?>
1 Like

this work correctly. thangk you

1 Like