Naveed Anjum
+92 313 514 6669

Author info in WordPress

If you are trying to display author info such as first name, last name, nice name, URL etc., in side the loop or out side the loop, here are some snippets to help you.

Out side the loop

In order to display author info out side the loop you need to add following piece of code.

global $post;
$author_id = $post->post_author;

//To display author first name.
$author_fname = get_the_author_meta( 'first_name', $author_id );

//To display author second name.
$author_lname = get_the_author_meta( 'last_name', $author_id );

//you can combine both names
$author_name = $author_fname .' '. $author_lname;

You can chose different parameters for the author here are some parameters

Author parameters

  • description
  • display_name
  • first_name
  • ID
  • last_name
  • nickname
  • user_description

Inside the loop

In order to display author info inside the loop you need to add following piece of code.

$author_id = get_the_author_meta( 'ID' );

//To display author first name.
$author_fname = get_the_author_meta( 'first_name', $author_id );
//To display author second name.

$author_lname = get_the_author_meta( 'last_name', $author_id );

//you can combine both names
$author_name = $author_fname .' '. $author_lname;

//to access author's post page
echo esc_url( get_author_posts_url( $author_id ) );
Previous Post Next Post

Leave a Reply

Your email address will not be published. Required fields are marked *