Skip to main content
4 of 4
the edit is better programming practice because it takes into account the possibility that the author name will not be set, in which case the accepted answer is not sufficient.
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

Try this code.

$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
echo $author->ID;

Alternatively, if author name has not been set use:

if ( $author_id = get_query_var( 'author' ) ) { $author = get_user_by( 'id', $author_id ); }

credit @AndyAdams in the easily missed comments bellow

Joshua Abenazer
  • 4.4k
  • 1
  • 25
  • 30