Support » Fixing WordPress » Show author’s first name and first letter/initial of last name.

  • Resolved Kevin Kwok


    Within my index.php I have a line of code that shows a summary of a post and the author’s first name. I would like to display the first name and last initial.

    example: “Barack O.

    line of code I have now: echo the_author_meta('first_name');

Viewing 6 replies - 1 through 6 (of 6 total)
  • I tried this :

    echo substr($the_author_lastname->last_name, 0, 1);


    echo substr(the_author_lastname(),0,1);

    didnt do anything =(

    Try this..

    $sep = ' '; // Seperator between first name and last initial (space currently)
    $ln_init = the_author_meta('last_name');
    echo the_author_meta('first_name') . $sep . $ln_init{0};

    hm tried that it seemed to to just display the the name like this


    thanks though.

    This is a snippet of my code :

    foreach($posts as $post){
    if(get_post_meta($post->ID, 'full-image', $single = true))
    	echo '<img class="full-image" src="'.get_post_meta($post->ID, 'full-image', $single = true).'"/>';
        echo '<img class="full-image" src="'.bloginfo('url').'" />';
        echo the_author_meta('first_name');
        echo ('&nbsp;');
        echo the_author_meta('last_name');

    but my latest fix is:

    if(strlen($the_author_lastname->lastint) >1){
    echo substr(last_lastint(),0,1);

    I’m so sure I’ve seen this before, I think if I am unable to figure it out maybe I can edit each profile and add a nickname to be “Barack O.” and just tell wordpress to display nickname, but I hope it does not come to that.



    Forum Moderator

    this worked in my setup (in the normal loop):
    <?php echo $authordata->first_name.' '.substr($authordata->last_name,0,1).'.'; ?>

    alternatively, using the_author_meta() and get_the_author_meta() :
    <?php the_author_meta('first_name'); ?> <?php echo substr(get_the_author_meta('last_name'),0,1); ?>.

    (ps: might need some adjustments to keep the output nice if some of the fields are empty)

    youre a genius it worked. I used your alternate method it was just missing a space and the period after the last initial so I changed it a little to this:

    <?php echo the_author_meta('first_name'); ?>
    <?php echo ('&nbsp;'); ?>
    <?php echo substr(get_the_author_meta('last_name'),0,1).'.'; ?>

    Thanks you. Thank you. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show author’s first name and first letter/initial of last name.’ is closed to new replies.