Skip to main content

benecaster_get_public_feed_url()

Feed Token Free
benecaster_get_public_feed_url( int $show_id ): ?string

Returns the canonical public (un-gated) feed URL for a show — the feed anyone can access without a subscriber token. It is the only builder of that URL in Benecaster: [benecaster_rss_link], the RSS Feed link in [benecaster_platform_links], the show’s QR code and the Shows REST API all call it, so they always agree.

Call it rather than assembling /podcast-feed/{slug}/ yourself. That is now only one of two correct shapes: with Use pretty feed URLs on (Settings → Permalinks), the public feed is advertised at /podcast/{slug}/feed/, and a hand-built URL would give your page a different address from every other surface on the site. Both shapes keep serving once the switch has ever been on, so a hand-built URL still works; it’s just not the one the podcaster chose. Use this from theme code, add-on callbacks, or template overrides whenever you need a “listen anywhere” public-tier link.

Never redirect a feed request to this URL. It is the exact URL the ^podcast-feed/([^/]+)/?$ rewrite rule dispatches straight back into FeedController::maybe_dispatch(), so a redirect issued from anywhere in the feed pipeline points at the request it was called on — an infinite loop, and one that a Cache-Control: public, max-age=3600 header would cache for an hour. A redirect issued before token resolution would hit anonymous requests too, so a stranger asking for the free public feed would get the loop. Feeds go dark with a 403 and there is no fallback redirect anywhere in the pipeline.

Rendering links is what it is for, and using it keeps your code in sync with any future change to the public feed URL structure.

Parameters

Name Type Default Required Description
$show_id int — Yes WordPress post ID of the show.

Return Value

Type: string|null

The fully-qualified public (un-gated) feed URL for the show, in the shape the Use pretty feed URLs switch currently selects: https://example.com/podcast/my-show/feed/ when it's on, https://example.com/podcast-feed/my-show/ when it's off. Returns null when the show has no feed slug configured.

Example

$public_url = benecaster_get_public_feed_url( 42 );
if ( $public_url ) {
    echo '<a href="' . esc_url( $public_url ) . '">Listen free</a>';
}

Notes

Returns null when the show's feed slug field is empty. Check the return value before using it in a link — and not in a redirect, per the warning above. The URL is not validated against the server: it is constructed from the stored slug and the site's home_url().

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