Skip to main content

benecaster_related_episodes_output

Filter Free

Filters the final rendered HTML of the benecaster_related_episodes shortcode and the Related Episodes Episode Page block, which renders through the shortcode’s pipeline. Use to change the list markup, wrap the output in a custom container element, or suppress the output entirely when there are no results. It fires when the list is empty too, with $html an empty string.

Parameters

Name Type Default Description
$html string — Rendered HTML output; empty when there are no results
$episodes WP_Post[] — Episode WP_Post objects used to generate the output
$atts array — Resolved shortcode attributes. For the block, the same keys built from its settings: `query` is the block's query type, `count` its count, `style` is `list`, `exclude_current` is `true` and `title` is "More episodes"

Returns: string

Examples

Wrap in accessible section element

add_filter( 'benecaster_related_episodes_output', function ( $html, $episodes, $atts ) {
    if ( empty( $episodes ) ) {
        return '';
    }
    return '<section class="related-episodes" aria-label="Related episodes">' . $html . '</section>';
}, 10, 3 );

Suppress output when no results

add_filter( 'benecaster_related_episodes_output', function ( string $html, array $episodes, array $atts ): string {
    if ( empty( $episodes ) ) {
        return '';
    }
    return '<section class="related-episodes">' . $html . '</section>';
}, 10, 3 );

Affects

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