Skip to main content
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.
Source Link
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 @ Andy Adams in the easily missed comments bellow :)credit @AndyAdams in the easily missed comments bellow

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 @ Andy Adams in the easily missed comments bellow :)

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

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.
Source Link

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 @ Andy Adams in the easily missed comments bellow :)

Try this code.

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

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 @ Andy Adams in the easily missed comments bellow :)

Code Correction
Source Link
Joshua Abenazer
  • 4.4k
  • 1
  • 25
  • 30

Try this code.

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

Try this code.

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

Try this code.

$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
echo $author->ID;
Source Link
Joshua Abenazer
  • 4.4k
  • 1
  • 25
  • 30
Loading