Get author first name with {author_name}

The dynamic tag {author_name} returns the full name of the author, how do i set it up to return only the first name e.g {author_name:f_name}. I do not wish to have it return the first name on a global level, just for specific elements. Thank you

You could write a quick PHP function

get_the_author_meta( ‘first_name’ );

and return that with {echo:my_function}

Thank you, i asked bing chat and it gave me the code below which worked.

function get_author_first_name() {
  // Get the author ID of the current post
  $author_id = get_the_author_meta('ID');
  // Get the author's first name using WordPress function
  $first_name = get_the_author_meta('first_name', $author_id);
  // Return the first name
  return $first_name;
}

I returned the author fname using {echo:get_author_first_name()}

Since get_author_first_name() is now deprecated, I used the following:

{echo:get_the_author_meta( ‘first_name’)}

Source: get_the_author_firstname() | Function | WordPress Developer Resources

1 Like

Since 1.9.1 you can use {author_meta:first_name}

1 Like