Skip to main content

benecaster_episode_nav_output

Filter Free

Filters the rendered HTML output of the [benecaster_episode_nav] shortcode before it is returned. $prev and $next are the resolved adjacent episode post objects after the benecaster_episode_nav_prev and benecaster_episode_nav_next filters have already run; each is null when no adjacent episode exists in that direction.

When the navigation is rendered via the episode_nav Episode Page block rather than the standalone shortcode, benecaster_episode_page_block_episode_nav fires in addition to this filter — it is an instance of the per-block pattern-group filter, which is documented once for every block slug rather than per slug. Use this filter to suppress the nav when no adjacent episodes exist, wrap it in an accessible nav element, or modify the markup in any other way.

Parameters

Name Type Default Description
$html string Rendered HTML output of the navigation
$prev WP_Post|null Resolved previous episode post object, or null if none
$next WP_Post|null Resolved next episode post object, or null if none
$atts array Resolved shortcode attributes

Returns: string

Examples

Suppress nav and wrap in nav element

add_filter( 'benecaster_episode_nav_output', function( $html, $prev, $next, $atts ) {
    // Suppress the nav entirely when no adjacent episodes exist.
    if ( ! $prev && ! $next ) {
        return '';
    }
    return '<nav class="episode-nav" aria-label="Episode navigation">' . $html . '</nav>';
}, 10, 4 );

Return empty when no adjacent episodes

add_filter( 'benecaster_episode_nav_output', function( string $html, ?WP_Post $prev, ?WP_Post $next, array $atts ): string {
    // Suppress nav entirely when there are no adjacent episodes
    if ( null === $prev && null === $next ) {
        return '';
    }
    return $html;
}, 10, 4 );

Notes

When the episode_nav block is rendered via the Episode Page rather than the standalone shortcode, benecaster_episode_page_block_episode_nav also fires — this filter fires in both contexts.

Affects

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