I have some code that executes in header.php as follows:

  if (is_author()) {
      $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
      $date = $curauth->user_registered;

I've tried to get this user information out of this code in a few different ways and can't seem to get the user object itself at all. It is null.

I was thinking maybe the user object isn't available at this stage at where it's being called, but Wordpress is accurately getting into is_author() code based on determining the current page is an author template.

What am I doing wrong?


If you are using this on author pages or in loop then you can simply use this.

echo the_author_meta( 'user_registered' );

This will output registration date of author.

So your function will become.

if ( is_author() ) {
    $curauth = ( isset($_GET['author_name']) ) ? get_user_by( 'slug', $author_name ) : get_userdata( intval($author) );
    $date = the_author_meta( 'user_registered' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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