WP PowerSuite
150+ modules in one suite — toggle only what you need. Zero runtime cost for features you leave off.
See Plans
On This Page
v 1.0.2
Last updated: 02/04/2026

Username Body Class

Body classes for logged-in username and user ID—useful for theme tweaks and personalization. Privacy note: the username and ID appear in the page HTML source for that logged-in user.

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.

 

Who is this for?
Agencies demoing staging sites can spotlight “You are viewing as client-x” styling. Enterprise support reproduces bugs faster when screenshots include body.user-id-4821. Training overlays can target pilot cohorts listed by WP user IDs exported from HR spreadsheets. Pair with Role Body Class when you need both coarse and fine-grained targeting.

Features

Dual Identifiers
Login slug and numeric ID cover human-readable and machine-friendly selectors.
Frontend and Admin Coverage
Authenticated dashboard pages inherit the same classes for continuity.
Sanitized Slugs
Non-alphanumeric characters in usernames map to safe class tokens per WordPress conventions.
Zero Configuration
Flip the module on—no settings UI for typical installations.

How It Works

1
Enable the Module
Enable "Username Body Class" under WP PowerSuite.
2
Log In as Sample Users
Inspect on homepage, single, and /wp-admin/ index.
3
Author Scoped CSS
Example: body.user-jane_smith .beta-toggle { display: flex; }
4
Purge Personalized Caches
If edge caches serve logged-in HTML incorrectly, fix cookie vary headers before relying on per-user CSS.
5
Remove Before Public Launches
Disable or narrow usage before exposing demos to untrusted audiences if login slugs are sensitive internally.
Performance Note
Adds two short strings to body_class for authenticated hits only. Anonymous traffic unaffected. Combine awareness with object caching strategies that key HTML per user only when necessary.

Installation & Activation

1
Install WP PowerSuite
Activate plugin.
2
Enable Username Body Class
Toggle on.
3
Confirm body_class()
Older themes missing the function need header fixes before classes appear.
4
Security Review
Decide if exposing logins in HTML violates policy; consider Role-only hooks as alternative.
Requirements
PHP 8.1 or higher WordPress 6.0 or higher Permission to manage options (Administrator) Theme calling body_class() on public templates

Use Cases

  • UserFlagging
    Feature flags for pilot customers identified by user ID list.
  • AdminStyling
    Admin-only celebratory CSS on anniversaries for specific accounts.
  • VisualBaselines
    Automated visual regression baselines keyed per service account.

Frequently Asked Questions

Troubleshooting

  • Classes missing while logged in
    Template omitted body_class(); optimization stripped attributes; page served from anonymous cache bucket.
  • Slug mismatch expectations
    Sanitizer may collapse punctuation—inspect actual class string in dev tools.
  • Too-specific CSS brittle
    Prefer role-based or capability-driven styling for long-term maintenance.