On This Page
Username Body Class
Overview
Username Body Class appends stable identifiers to the HTML body element whenever a session is authenticated: a sanitized login slug (user-{login}) and numeric user ID (user-id-{id}). Logged-out visitors do not receive these tokens. The front end and wp-admin both reflect the classes, giving designers and support engineers a hook to tailor experiences per account—banner text, debug outlines, or admin density—without embedding PII in JavaScript globals.
Because login names appear in page source, treat this as semi-public metadata: avoid enabling on highly sensitive extranets if policy forbids disclosing login handles, even though they are often guessable from author archives.

Features
Dual Identifiers
Frontend and Admin Coverage
Sanitized Slugs
Zero Configuration
How It Works
Enable the Module
Log In as Sample Users
Author Scoped CSS
Purge Personalized Caches
Remove Before Public Launches

Installation & Activation
Install WP PowerSuite
Enable Username Body Class
Confirm body_class()
Security Review

Use Cases
- UserFlaggingFeature flags for pilot customers identified by user ID list.
- AdminStylingAdmin-only celebratory CSS on anniversaries for specific accounts.
- VisualBaselinesAutomated visual regression baselines keyed per service account.
Frequently Asked Questions
Does this expose usernames?
Yes, in HTML source and some proxies’ logs. Weigh against convenience; use Role classes for less specific targeting.
What if logins change?
Class tokens follow current login on next session—update CSS when HR renames accounts.
Multisite user IDs global?
User IDs are network-wide numerics but site roles differ—test per blog.
Conflicts with caching plugins?
Ensure logged-in users bypass full-page cache or receive vary-by-cookie behavior.
Combine with OAuth or SSO?
Mapped WordPress users still get classes after login completes.
Troubleshooting
- Classes missing while logged inTemplate omitted body_class(); optimization stripped attributes; page served from anonymous cache bucket.
- Slug mismatch expectationsSanitizer may collapse punctuation—inspect actual class string in dev tools.
- Too-specific CSS brittlePrefer role-based or capability-driven styling for long-term maintenance.
