benecaster_feed_item_xml
Filters the compiled XML string for a single episode feed item, immediately after the episode data array has been serialized to XML. The `$xml` parameter is a complete `
For standard RSS fields, prefer [benecaster_feed_episode_data](/hooks/benecaster_feed_episode_data/) — that filter provides structured access to all fields before serialization and is more maintainable than string-manipulating the compiled XML. Use this filter when you need to inject elements from a custom XML namespace (such as `myns:customField`) that have no corresponding key in the episode data array. This filter fires once per episode per tier per feed compilation — keep callbacks lightweight.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$xml |
string |
— | The compiled XML fragment for this episode — a complete ... block |
$episode_id |
int |
— | ID of the episode |
$show_id |
int |
— | ID of the show |
$tier_slug |
string |
— | Tier slug for this feed compilation pass |
Returns:
string
Examples
Append custom dc:creator tag per item
add_filter( 'benecaster_feed_item_xml', function( $xml, $episode_id, $show_id, $tier_slug ) {
// Append a custom <dc:creator> tag to every episode item.
$host = get_post_meta( $show_id, '_benecaster_host_name', true );
if ( $host ) {
$xml .= '<dc:creator>' . esc_xml( $host ) . '</dc:creator>';
}
return $xml;
}, 10, 4 );
Inject custom namespace element before closing tag
add_filter( 'benecaster_feed_item_xml', function ( string $xml, int $episode_id, int $show_id, string $tier_slug ): string {
$tag = '<myns:episodeId>' . (int) $episode_id . '</myns:episodeId>';
return str_replace( '</item>', $tag . '</item>', $xml );
}, 10, 4 );
Notes
Prefer benecaster_feed_episode_data for modifying standard RSS fields — it provides structured access before serialization and is safer than string manipulation. Premium users can use benecaster_rss_extra_item_tags as a cleaner alternative for appending XML to each item. This is a Free filter — it fires regardless of license status.
See also: benecaster_feed_xml — filter the complete compiled feed XML after all items are assembled.