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

I'm making some changes in my theme. I want that when they visit a Post the header should contain the post author and his URL. right now I'm using this:

echo '<a href="'.get_author_posts_url().'">'.get_userdata($posts[0]->post_author)->data->display_name.'</a>;

the auhtor's display name is working correctly, but the link is going like


instead of this (for example)


so this is the code in the header

<a href="http://www.mysite.com/?author=0">Display name</a>

instead of this:

<a href="http://www.mysite.com/?author=36">Display name</a>

by the way: I'm doing this outside a loop.

share|improve this question

You are probably calling it too early and the context for the current post is not filled yet. get_author_posts_url() accepts author's ID as first argument, You probably need to retrieve and pass that to it, similar to how you retrieve the info for following call.

share|improve this answer
thanks, that was the problem. – Ali Saleem Dec 20 '13 at 17:46
up vote 0 down vote accepted

for anyone who's having this problem,this is the code I used:

 echo '<a href="'.get_author_posts_url(get_userdata($posts[0]->post_author)->data->ID).'">'.get_userdata($posts[0]->post_author)->data->display_name.'</a>';
share|improve this answer

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.