Skip to main content

benecaster_episode_chapters

Filter Free Since v1.0.0

Filters the chapter list before it is rendered on the front-end episode page. The filtered array is passed to templates/episode/chapters.php — return an empty array to suppress the chapter section entirely on this render pass.

This filter does NOT affect RSS output. The feed compilation path reads chapters directly from _benecaster_chapters post meta via PscChapterProvider and PodcastChaptersUrlProvider. Modifications made here are front-end only.

Safe uses: drop rows conditionally (by subscriber tier, login state, or title heuristics), reorder rows, rewrite timestamps to apply a per-request offset, or append synthesized rows. Injecting HTML into the title field is NOT safe — the template calls esc_html( $title ) before output, which will escape any markup to literal entities.

Parameters

Name Type Default Description
$chapters array Array of chapter rows. Each row: `{timestamp: string HH:MM:SS, title: string, url?: string, image_id?: int}`. Return an empty array to suppress the section entirely.
$episode_id int WordPress post ID of the episode being rendered
$show_id int WordPress post ID of the show the episode belongs to

Returns: array

Examples

Hide chapters marked as sponsor reads for logged-in subscribers

add_filter( 'benecaster_episode_chapters', function( array $chapters, int $episode_id, int $show_id ): array {
    if ( is_user_logged_in() ) {
        $chapters = array_values( array_filter(
            $chapters,
            fn( $c ) => stripos( $c['title'] ?? '', 'sponsor' ) === false
        ) );
    }
    return $chapters;
}, 10, 3 );

Notes

To add image markup next to chapter titles, override the template at {theme}/benecaster/episode/chapters.php rather than modifying the title field. The image_id field is available on each row after this filter runs — use wp_get_attachment_image( $image_id, [40, 40] ). See the add-chapter-image-to-front-end-list recipe for a full walkthrough.

Affects

  • Episode page chapter list