In WordPress, You can use the get_the_author_meta() function to get the author name. With the help of this, you can also get the author’s other details like first name, last name, nickname, email, id, etc.
Get Author Name in WordPress
$author_name = get_the_author_meta( 'display_name' ); echo $author_name; //This will give output the author name
Get Author First Name & Last Name in WordPress
$author_first_name = get_the_author_meta( 'user_firstname' ); echo $author_first_name; // This will display the author first name $author_last_name = get_the_author_meta( 'user_lastname' ); echo $author_last_name; // This will display the author last name
Get Author Name by Author ID in WordPress
To get the author name by author id, you can pass the author id as the second parameter within the get_the_author_meta() function.
Let’s say the author id is 5, and I want to get the author name for this author id.
$author_name = get_the_author_meta( 'display_name', '5' ); echo $author_name; // this will display the author name for the author id 5
You can also use get_the_author_meta(‘ID’) as the second parameter to get the author ID dynamically. As shown in the example below.
$author_name = get_the_author_meta( 'display_name', get_the_author_meta('ID') ); echo $author_name;