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 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
| Field | Arguments | Returns | Description |
|---|---|---|---|
id | — | int | User ID |
slug | — | string | User slug (nicename) |
user_email | — | string | Email address (requires list_users) |
display_name | — | string | Display name |
user_url | — | string | Website URL |
link | — | string | Author archive URL |
path | — | string | Author archive path |
edit_link | — | string | null | Admin edit URL (null when not authorized) |
profile_link | — | string | null | Profile page URL (null when not authorized) |
avatar | size or {options} | string | Avatar URL |
roles | — | array | null | User roles (null when no roles) |
is_current | — | bool | Is the current logged-in user |
can | capability, ...args | bool | Check user capability |
can_edit | — | bool | Can edit this user |
meta | field_name | mixed | User meta value (also used for first_name, last_name, nickname, description) |
raw_meta | field_name | mixed | Unescaped meta value |
has_field | field_name | bool | Check if field exists |
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:
| Field | Returns | Description |
|---|---|---|
ID | int | User ID (alias of id) |
user_login | string | Username (requires list_users) |
user_nicename | string | URL-friendly slug (alias of slug) |
user_registered | string | Registration 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') }}
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') }}
Author link
<a href="{{ author.link }}">{{ author.name }}</a>