This is probably a super simple question.
But how do I echo the ID of a user on author.php?
I’ve tried
the_author_meta('ID')
But it didn’t seem to want to work. I want to echo it at the end of a URL, for example;
http:///www.domain.com/author/sampleauthor-id
Obviously, where “id” is that particular author’s ID
Any ideas?
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