benecaster_user_badge_shortcode_output
Filters the full rendered HTML output of the [benecaster_user_badge] shortcode after the badge chips have been assembled into their wrapper element. The filter fires even when $html is an empty string — for example, when the user has no badges or no user can be resolved from the shortcode attributes. The output at this point is already escaped by the chip renderer.
The benecaster_user_badges filter runs earlier, inside the badge-fetching function, so the $badges array passed here reflects any modifications applied by that earlier filter. Return an empty string to suppress all shortcode output.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$html |
string |
— | Rendered badge chips HTML; empty string when no badges to display |
$badges |
array |
— | Array of badge row objects that were rendered |
$user_id |
int |
— | WordPress user ID whose badges are rendered |
$show_id |
int|null |
— | Show ID passed to the shortcode; null when not provided (site-wide badge scope) |
Returns:
string
Examples
Wrap chips in custom container
add_filter( 'benecaster_user_badge_shortcode_output', function (
string $html, array $badges, int $user_id, ?int $show_id
): string {
if ( empty( $html ) ) {
return $html;
}
return '<div class="my-badge-container">' . $html . '</div>';
}, 10, 4 );
Replace with custom chip template
add_filter( 'benecaster_user_badge_shortcode_output', function (
string $html, array $badges, int $user_id, ?int $show_id
): string {
ob_start();
foreach ( $badges as $badge ) {
echo '<span class="my-chip my-chip--' . esc_attr( $badge['icon_slug'] ?? 'none' ) . '">';
echo esc_html( $badge['label'] );
echo '</span>';
}
return ob_get_clean();
}, 10, 4 );
Affects
- [benecaster_user_badge] shortcode