WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is probably a super simple question.

But how do I echo the ID of a user on author.php?

I've tried


But it didn't seem to want to work. I want to echo it at the end of a URL, for example;


Obviously, where "id" is that particular author's ID

Any ideas?

share|improve this question
Not the permalinks, its for a modified version of the UserPhoto plugin. I want to hardcode a particular image link into author.php and as each user's images are appeneded with their author ID I need to include that in the link – Dean Elliott Dec 1 '11 at 10:54
up vote 12 down vote accepted

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

share|improve this answer
This gives me a 500 internal server error – Dean Elliott Dec 1 '11 at 11:01
Are you sure it is because of the above code.. could I have a look at your author.php? – Joshua Abenazer Dec 1 '11 at 11:05
$author = get_user_by( 'slug', get_query_var( 'author_name' ) ); gave no problems, it was the echo author->ID; that caused the error for some reason – Dean Elliott Dec 1 '11 at 11:07
Oops there is a typo.. its echo $author->ID... notice the '$'. Updated the answer. – Joshua Abenazer Dec 1 '11 at 11:08
Both of you missed a dollar sign. echo $author->ID; – Johannes Pille Dec 1 '11 at 11:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.