Skip to main content

benecaster_rss_extra_item_tags

Filter Free

Adds elements to each episode’s <item> that benecaster_feed_episode_data has no key for — a sponsor line, a chapters file from another service, a custom CMS field. Return an array of tags; Benecaster writes and escapes the XML, so a mistake here cannot break the feed. They render last, just before </item>, and benecaster_feed_item_xml sees them.

Same shape and rules as benecaster_rss_extra_channel_tags: 'prefix:name' => 'text', or [ 'value' => …, 'attributes' => [ … ] ], an empty value self-closes, anything unusable is dropped, one element per name, and a custom prefix must be declared through benecaster_feed_namespaces.

Fires once per episode, per tier, per feed compilation — keep callbacks lightweight.

Add a custom field to the RSS feed

Free Intermediate

Two hooks work in combination here: benecaster_episode_custom_fields exposes a custom field’s value through the episode data layer, and benecaster_rss_extra_item_tags appends the corresponding XML to each RSS item. Use this pattern when you need a non-standard namespace element (e.g. a sponsor tag, a transcript URL, or a custom CMS field) in the feed.

<?php
add_filter(
    'benecaster_rss_extra_item_tags',
    function ( array $tags, int $episode_id, int $show_id ): array {
        $sponsor = benecaster_get_field( 'sponsors', $episode_id );
        if ( is_string( $sponsor ) && '' !== $sponsor ) {
            $tags['myshow:sponsor'] = $sponsor;
        }
        $count = (int) get_post_meta( $episode_id, '_my_addon_chapter_count', true );
        if ( $count > 0 ) {
            $tags['myshow:chapterCount'] = [
                'value'      => (string) $count,
                'attributes' => [ 'unit' => 'chapters' ],
            ];
        }
        return $tags;
    },
    10,
    3
);

View on GitHub →

Parameters

Name Type Default Description
$tags array Tags to add, keyed by element name. Empty by default.
$episode_id int ID of the episode
$show_id int ID of the show
$tier_slug string Tier slug for this feed compilation pass (`public` for the public feed)

Returns: array

Example

add_filter( 'benecaster_rss_extra_item_tags', function ( array $tags, int $episode_id ): array {
    $url = (string) get_post_meta( $episode_id, '_my_chapters_json_url', true );
    if ( '' !== $url ) {
        $tags['podcast:chapters'] = [
            'value'      => '',
            'attributes' => [ 'url' => $url, 'type' => 'application/json+chapters' ],
        ];
    }
    return $tags;
}, 10, 2 );

Notes

Built 2026-09-18. An earlier version of this page described a raw XML string; the published recipes used this array shape, and the array is what shipped — it is the one a caller cannot use to produce an unparseable feed.

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