How to get author ID when an author page is being viewed?

wp_loaded is too early, the request hasn’t been parsed yet – use the action wp instead (called at the end of WP::main(), once the request has been parsed and posts have been queried).

To get the user object, just use $author = get_queried_object();

Leave a Comment