Skip to main content

benecaster_latest_episode_output

Filter Free Since v1.0.0

Filters the final rendered HTML of the [benecaster_latest_episode] shortcode before it is returned to the page. Use to alter the markup, inject schema.org/PodcastEpisode structured data, add analytics wrappers, or adjust the player style included in the output.

This filter fires only when an episode was successfully resolved — it does not fire when benecaster_latest_episode_id returns null. The $atts array includes the resolved shortcode attributes: show_id, sections, style, and link_title.

Parameters

Name Type Default Description
$html string Rendered HTML output
$episode_id int ID of the resolved latest episode
$atts array Resolved shortcode attributes including show_id, sections, style, and link_title

Returns: string

Examples

Inject schema.org structured data block

add_filter( 'benecaster_latest_episode_output', function( $html, $episode_id, $atts ) {
    $permalink = get_permalink( $episode_id );
    $title     = get_the_title( $episode_id );
    $ld = '<script type="application/ld+json">{"@context":"https://schema.org","@type":"PodcastEpisode","url":"' . esc_url( $permalink ) . '","name":"' . esc_js( $title ) . '"}</script>';
    return $ld . $html;
}, 10, 3 );

Append custom schema from helper function

add_filter( 'benecaster_latest_episode_output', function( string $html, int $episode_id, array $atts ): string {
    $schema = my_build_episode_schema( $episode_id );
    return $html . '<script type="application/ld+json">' . wp_json_encode( $schema ) . '</script>';
}, 10, 3 );

Notes

Does not fire when benecaster_latest_episode_id returns null.

Affects

  • [benecaster_latest_episode] shortcode