Skip to main content

benecaster_psc_chapters

Filter Free Since v1.0.0

Filters the chapter list injected into the `psc:chapters` RSS element for an episode. The default is an empty array, which means no `psc:chapters` output is produced for the episode.

Return an array of chapter objects to enable Podlove Simple Chapters output in your RSS feed. Each object must include at minimum a `start` key (a timecode string in `HH:MM:SS.mmm` format) and a `title` key (string). Optional keys are `href` (a URL associated with the chapter) and `image` (a URL for a chapter thumbnail). For Podcasting 2.0 `podcast:chapters` JSON output, see [benecaster_podcast_chapters](/hooks/benecaster_podcast_chapters/).

Parameters

Name Type Default Description
$chapters array Chapter objects array; default []. Each item: {start: string, title: string, href?: string, image?: string}
$episode_id int ID of the episode

Returns: array

Examples

Load chapters from post meta JSON

add_filter( 'benecaster_psc_chapters', function( $chapters, $episode_id ) {
    // Load Podlove Simple Chapters from a JSON blob stored in post meta.
    $raw = get_post_meta( $episode_id, '_psc_chapters_json', true );
    if ( $raw ) {
        $decoded = json_decode( $raw, true );
        if ( is_array( $decoded ) ) {
            return $decoded; // Each item must have 'start' and 'title' keys.
        }
    }
    return $chapters;
}, 10, 2 );

Affects

  • psc:chapters RSS element (Podlove Simple Chapters)