Wordpress - Get author full name
Try the following:
<?php
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$full_name = '';
if( empty($fname)){
$full_name = $lname;
} elseif( empty( $lname )){
$full_name = $fname;
} else {
//both first name and last name are present
$full_name = "{$fname} {$lname}";
}
echo $full_name;
?>
The get_the_author
can directly be used to display the name of the author. There are few settings to be done on the admin for this:
- Under the user settings add make sure you have the first and last name fields filled up.
- After that see for the
Display name publicly as
options and select whichever format you want the name to be shown. - Click save and refresh your page.