WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress Get the Author Outside Loop


This tutorial explains how to get the current Post Author outside of the WordPress Loop.

For the author-archive views generated by my shapeSpace starter theme, I needed a way to display author information outside of the Loop. This article explains two ways to make it happen..

Method 1

This method uses the WP API and is the cleanest way of getting author information outside of the Loop:

..which may be simplified like this:

As written, that code displays the author’s Display Name. To instead get the entire WP_User object, the code can be modified as follows:

Then you can call any method or property of WP_User to get whatever author information is required. Here is an advanced example of this, as featured in the shapeSpace theme:

So pretty much you can get whatever author/user infos you need, even outside of the WordPress Loop.

Method 2

Here is an alternate method that uses the global $post object along with get_the_author_meta() to retrieve the author’s Display Name:

To get other author details, you can change the first parameter of get_the_author_meta().

Learn more

WordPress Themes In Depth

Show Support

Like our new Facebook Page to show support!