benecaster_explicit_badge_html
Replaces the badge’s entire rendered markup. The escape hatch for what the label filter and CSS cannot reach — injecting an icon, restructuring the element, wrapping it in something your theme needs.
Try CSS first. The default markup already carries two class modifiers, --{mode} and --context-{surface}, so restyling per mode and per surface usually needs no PHP at all. This filter is for structural changes, not cosmetic ones.
If you replace the markup, you own the accessibility. The default output carries role="img" and an aria-label, because a badge that conveys meaning through colour or a single letter is unreadable to a screen reader. Anything returned here needs an equivalent — a visually-hidden text span, or an aria-label on the replacement element.
Clean episodes render an empty string by default. A filter that returns non-empty markup for 'clean' puts a badge on every episode in the catalogue, which is rarely the intent. Guard on the mode and return the incoming value untouched for clean, unless a “Clean” chip everywhere is deliberately what you want.
Restyle or reword the Explicit badge
The Explicit badge is rendered by one class — Benecaster\Episode\ExplicitBadgeRenderer — from every surface it appears on: the episode single page, archive cards, the [benecaster_episodes] list, the [benecaster_player] title strip, and the [benecaster_explicit_badge] shortcode. All of them share the same three filters, so a single hook changes the badge everywhere rather than needing a template override per surface.
Three asks come up repeatedly, and each maps to exactly one filter. Pick the smallest one that does the job.
“Change the wording.” Use the label filter. “E”, “18+”, “Adult”, your own phrasing — all one line, and the accessibility attributes and class modifiers stay intact.
“Restyle it.” Usually no PHP at all. The markup already carries --{mode} and --context-{surface} class modifiers, so CSS can style explicit differently from clean, and the archive grid differently from the single page. Reach for the HTML filter only when you need to change the structure — injecting an icon, say — not the appearance.
“Force it on for this one episode.” Use the mode filter. It overrides the resolved value without writing to the episode, which keeps a one-off out of your stored data.
<?php
// 1. Replace "Explicit" with a short "E" everywhere the badge renders.
add_filter( 'benecaster_explicit_badge_label', function ( string $label, string $mode ): string {
return 'clean' === $mode ? $label : 'E';
}, 10, 2 );
// 2. Restyle without touching templates — the class list already carries
// two modifiers (--{mode} + --context-{surface}), so plain CSS handles
// most cases. The HTML filter is the escape hatch when class-only styling
// is not enough (e.g. injecting an <svg> icon for aria-hidden purposes).
add_filter( 'benecaster_explicit_badge_html', function ( string $html, int $episode_id, int $show_id, string $mode, string $context ): string {
if ( 'clean' === $mode ) {
return $html; // leave the empty string alone
}
return sprintf(
'<span class="my-explicit" role="img" aria-label="%s"><svg aria-hidden="true"></svg><span class="visually-hidden">%s</span></span>',
esc_attr__( 'Explicit content', 'my-theme' ),
esc_html__( 'Explicit', 'my-theme' )
);
}, 10, 5 );
// 3. Force the badge on a specific episode without touching the stored
// meta — useful for a one-off override during a special series.
add_filter( 'benecaster_explicit_badge_mode', function ( string $mode, int $episode_id, int $show_id ): string {
return 12345 === $episode_id ? 'yes' : $mode;
}, 10, 3 );
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$html |
string |
— | Default rendered markup. Empty string when the mode is `'clean'` and the caller did not opt into showing clean badges. |
$episode_id |
int |
— | WordPress post ID of the episode. |
$show_id |
int |
— | WordPress post ID of the show. |
$mode |
string |
— | The resolved mode — `'clean'`, `'yes'`, or `'explicit'`. |
$context |
string |
— | Where the badge is rendering — `'single'`, `'card'`, `'list'`, `'player'`, or `'shortcode'`. Use it to vary the badge by surface: an icon in the archive grid, full text on the episode page. |
Returns:
string
Examples
Replace with an icon badge that stays accessible
add_filter( 'benecaster_explicit_badge_html', function ( string $html, int $episode_id, int $show_id, string $mode, string $context ): string {
if ( 'clean' === $mode ) {
return $html;
}
return sprintf(
'<span class="my-explicit" role="img" aria-label="%s"><svg aria-hidden="true"></svg><span class="visually-hidden">%s</span></span>',
esc_attr__( 'Explicit content', 'my-theme' ),
esc_html__( 'Explicit', 'my-theme' )
);
}, 10, 5 );
Render the badge only on the single-episode page
add_filter( 'benecaster_explicit_badge_html', function ( string $html, int $episode_id, int $show_id, string $mode, string $context ): string {
return 'single' === $context ? $html : '';
}, 10, 5 );