Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to display the first and last name of an author without having to change the "Display publicly as..." setting. Problem is, I can only seem to find solutions for either or, or at best display/nice/nickname. I would like to display the full name no matter what the user/author has chosen to "Display publicly as".

Ideally I'd like to combine the below if possible.

get_the_author_meta('first_name') 

and

get_the_author_meta('last_name') 

Any help would be appreciated!

EDIT (FINAL CODE):

$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}";
        }

        $nicknames = "";
        //get_author_role()
        $userjob = get_cimyFieldValue(get_the_author_meta('ID'), 'JOBTITLE');
        //$userjob = "";
        ob_start();
        coauthors_links();
        //coauthors_firstname();
        $authornames = $full_name;
        ob_end_clean();

        if (empty($authornames)) { 
            $authornames = get_the_author();
        } else {
            $userjob = NULL;
        }
        $linkpre = "<a href='/author/".get_the_author_meta('user_nicename')."'>";
        $linkpost = "</a>";
        if (custom_author_byline("") !== ""){
            $authornames = get_the_author();
            $linkpre = $linkpost = "";
            $userjob = NULL;
        }
        //echo coauthors_links();
        //get_the_author_meta("nickname")
        echo "<p class='authormet'>By ".$linkpre.$authornames.$linkpost."</p><br/><p class='authormet'>".$categories_list." | ".get_the_date()."</p>";
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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;
?>
share|improve this answer
2  
Why not just echo trim( "$fname $lname" );? –  toscho Feb 7 '13 at 15:31
    
Thanks, I'm really close now! Adding the above outputs the name twice though. I'm probably overlooking something simple, I've added sample code above. –  kallekillen Feb 7 '13 at 15:32
1  
remove the first echo $full_name; ;-) –  Mike Madern Feb 7 '13 at 15:35
    
haha of course, thank you! –  kallekillen Feb 7 '13 at 15:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.