Skip to main content

benecaster_render_user_badges()

Membership Free
benecaster_render_user_badges( int $user_id = 0, ?int $show_id = null ): string

Renders a subscriber’s badge chips as HTML, so a theme can show them anywhere without knowing how badges are stored or styled. The markup matches the chips on the account page and the Supporter Wall, and it picks up the badge stylesheet the same way they do.

The output is already escaped. Print it as it comes — escaping it again renders the markup as visible text instead of badges, which is the usual way this goes wrong.

It looks badges up through benecaster_get_user_badges(), so the benecaster_user_badges filter applies and any add-on that adds or reorders badges is respected here too.

It does its own lookup on every call, which makes it the wrong choice inside a loop over many subscribers — that is one query per row. For a directory or a list, fetch the badges yourself and render them from what you already hold.

Parameters

Name Type Default Required Description
$user_id int 0 No WordPress user ID. Defaults to the current logged-in user. Pass an explicit ID when rendering somebody else's badges — in a comment byline or a members directory, where the current user is the viewer, not the subject.
$show_id ?int null No Optional show context, passed straight through to the badge filter so a per-show surface can scope what it displays.

Return Value

Type: string

The subscriber's badge chips as HTML, ready to print. An empty string when there is no user to resolve or the user has no badges — so it is safe to echo unconditionally without producing an empty wrapper.

Example

// In a theme template — an author box, a comment byline, a members directory row.
echo benecaster_render_user_badges( $author_id );

Hooks Fired

Need this built rather than just documented? See our services →