Skip to main content

User

Access user data. The user root provider represents the currently logged-in visitor and is available on all pages.

The author variable uses the same provider but resolves to the post's author instead. See the overview for details.

user vs author

user and author expose the same fields listed below. The only difference is which person they point to: user is whoever is viewing the page, author is whoever wrote the post.

All Fields​

FieldArgumentsReturnsDescription
id—intUser ID
slug—stringUser slug (nicename)
user_email—stringEmail address (requires list_users)
display_name—stringDisplay name
name—stringDisplay name (alias of display_name)
user_url—stringWebsite URL
link—stringAuthor archive URL
path—stringAuthor archive path
edit_link—string | nullAdmin edit URL (null when not authorized)
profile_link—string | nullProfile page URL (null when not authorized)
avatarsize or {options}stringAvatar URL
roles—array | nullUser roles (null when no roles)
is_current—boolIs the current logged-in user
cancapability, ...argsboolCheck user capability
can_edit—boolCan edit this user
metafield_namemixedUser meta value (also used for first_name, last_name, nickname, description)
raw_metafield_namemixedUnescaped meta value
has_fieldfield_nameboolCheck if field exists
Restricted fields

user_login, user_email, user_registered, roles, meta, raw_meta, and has_field require the list_users capability.

Raw Database Fields​

Direct read access to the underlying WP_User columns:

FieldReturnsDescription
IDintUser ID (alias of id)
user_loginstringUsername (requires list_users)
user_nicenamestringURL-friendly slug (alias of slug)
user_registeredstringRegistration date YYYY-MM-DD HH:MM:SS (requires list_users)

Profile​

Profile fields like first/last name, nickname, and biographical info are accessed through meta() (matching how WordPress stores them):

{{ user.display_name }}
{{ user.meta('first_name') }} {{ user.meta('last_name') }}
{{ user.meta('nickname') }}
{{ user.meta('description') }}
{{ user.user_url }}

Avatar​

The avatar field accepts either a size in pixels or an options object:

{{ user.avatar }}                                       <!-- Default size -->
{{ user.avatar(96) }} <!-- 96px size -->
{{ user.avatar({size: 200, default: 'identicon'}) }} <!-- Custom options -->

Roles & Capabilities​

{{ user.roles|join(', ') }}
{{ user.is_current }}
{{ user.can('edit_posts') }}
{{ user.can('manage_options') }}
{{ user.can('edit_post', post.id) }} <!-- Variadic — pass extra args for meta-capabilities -->

To check whether a visitor is logged in, compare user.id (it's 0 for guests):

{{ user.id ? 'Welcome back!' : 'Please log in' }}

Custom Fields (Meta)​

{{ user.meta('phone') }}
{{ user.meta('company') }}
{{ user.meta('billing_address').city }}
{{ user.has_field('phone') }}
Plugin integration

meta('key') integrates with ACF, MetaBox, JetEngine, and Pods. Private meta keys (starting with _) are blocked for security.

Common Patterns​

Show content for logged-in users​

{{ user.id ? 'Welcome back!' : 'Please log in' }}

Display user greeting​

Hello, {{ user.name ?? 'Guest' }}

Check admin capability​

{{ user.can('manage_options') ? 'Admin Panel' : '' }}

Author bio​

{{ author.name }}
{{ author.meta('description') }}
{{ author.avatar(96) }}

"Posted by" line​

Posted by {{ author.name }} on {{ post.date('F j, Y') }}
<a href="{{ author.link }}">{{ author.name }}</a>