Within a post I can use the_author() to retrieve the author name, but in the sidebar of a single-post page this does not return anything. How to get metadata on the post author outside the post?

  • Be careful with those template tags. Some are intended for use inside the Loop and do not work reliably outside it. Check the Codex if aren't sure. – s_ha_dum Mar 24 '13 at 17:37

Test whether on a single post. If so, get a user object by the current posts' author ID and echo its display_name property:

if ( is_single() ) {
    global $post;

    $author = get_userdata( $post->post_author );
    echo $author->display_name;
| improve this answer | |

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.