Keep web-only markup out of the RSS feed
benecaster_episode_content runs on the episode page and again while each subscriber feed is built, so whatever your callback adds ends up in both. That is a problem for anything interactive: podcast apps run no JavaScript, so a comments widget, an embed or a script-revealed element is dead weight in a feed, or never shows at all.
The filter’s arguments can’t tell you which you’re in, because its third argument is a tier slug on the episode page and in the feed alike. Ask FeedCompiler::is_compiling() instead. It is true only while a feed is being built, including from cron and cache rebuilds. The example adds an interactive widget to episode pages and a plain link in feeds.
Read it; never set it. FeedCompiler::within_compilation() is how Benecaster marks a feed build. Calling it yourself makes a web page look like a feed to every callback that asks.
Feeds are cached per tier, so a change to what your callback emits in a feed shows after the next rebuild. Save an episode or clear the feed cache to see it.
Code
<?php
// An interactive embed on episode pages, a plain link in feeds: podcast apps run no JavaScript.
add_filter( 'benecaster_episode_content', function ( string $content, int $episode_id ): string {
$url = get_permalink( $episode_id );
if ( \Benecaster\Feed\FeedCompiler::is_compiling() ) {
return $content . '<p><a href="' . esc_url( $url ) . '">Join the discussion</a></p>';
}
return $content . '<div class="my-comments-widget" data-episode="' . (int) $episode_id . '"></div>';
}, 20, 2 );
Hooks Used
Need this built rather than just documented? See our services →