Skip to main content

benecaster_explicit_badge_html

Filter Free

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.

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 );

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