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.

2 Answers 2


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.


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>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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