I am trying to get author information in my header.php.

This is what I use to display the name and it works like a charm:

<?php $author_id=$post->post_author; ?><?php echo the_author_meta( 'display_name' , $author_id ); ?>

I also wanted to get the author's URL so I changed the code to

<?php $author_id=$post->post_author; ?><?php echo the_author_meta( 'user_url' , $author_id ); ?>

but this doesn't work.

  • What are you hoping to get the author for? Which post? – shea Jan 9 '13 at 9:19

I just put a piece of code from author.php file of TwentyTwelve theme:

    /* Queue the first post, that way we know
     * what author we're dealing with (if that is the case).
     * We reset this later so we can run the loop
     * properly with a call to rewind_posts().

<header class="archive-header">
    <h1 class="archive-title"><?php printf( __( 'Author Archives: %s', 'twentytwelve' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' ); ?></h1>
</header><!-- .archive-header -->

    /* Since we called the_post() above, we need to
     * rewind the loop back to the beginning that way
     * we can run the loop properly, in full.

Pay attention to how they get an author posts link. At the beginning they call the_post function outside the main loop to fetch first post. Then they get author information, like posts URL and display name. And finally they call rewind_posts function to reset loop.

You can use the same technique in your header.php file.


the_author_meta( 'user_url' ) will retrieve the website URL as set in the author's profile. You need to use the_author_meta( 'url' ) to display a link to the author post archive:

global $post;
$author_id = $post->post_author;
the_author_meta( 'url' , $author_id );

Also note that you don't need to echo anything, as the_author_meta() already displays it for you.

  • It is giving me page permalink – vaibhav Jan 9 '13 at 8:55
  • See my updated answer – shea Jan 9 '13 at 9:27
  • still the same giving me page permalink – vaibhav Jan 9 '13 at 14:27

You can use get_the_author_link() function to get the url pointing to the author.

Also you can use the_author_link() to display the author link.


You might get help with this.


global $post;
the_author_meta( $field, $author_id );
  • 1
    as i said i am using the codes outside the loop – vaibhav Jan 9 '13 at 8:56

Use get_author_posts_url() function to get the author link outside of loop.

global $post;

echo get_author_posts_url($author_id);
  • Note that this retrieves the URL to the author page for the user, and not the URL to their website they added in their profile. – swissspidy Jan 25 '18 at 12:22

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.