Add An External Podcast Feed to Your WordPress Site’s Feeds

WordPress Podcast Feed Functions

A popular podcast online utilizes WordPress as their publishing platform for the information about their podcast as well as publishing a ton of information about each show. However, they actually host the podcast itself on an external podcast hosting engine. It’s pretty seamless to the site’s visitors – but lacks one feature that’s invisible to users but visible to crawlers like Google.

Google specifies this in their support:

In addition, if you associate your RSS feed with a homepage, users searching for your podcast by name can get a description of your podcast as well as a carousel of episodes for your show on Google Search. If you do not provide a linked homepage, or Google can’t guess your homepage, your episodes can still appear in Google Search results, but only grouped with episodes from other podcasts on the same topic.

Google – Get your podcast on Google

 With the two associated, you can get some nice coverage in Google:

Podcasts on Google SERP

The crawling of the site reveals a blog post feed, but not the actual podcast feed – which is externally hosted. The company wants to keep its current blog feed, so we want to add an additional feed to the site. Here’s how:

  1. We need to code a new feed within their WordPress theme.
  2. We need to retrieve and publish the external podcast feed in that new feed.
  3. We need to add a link in the head of the WordPress site that displays the new feed URL.
  4. Bonus: We need to clean up the new podcast feed URL so we don’t have to depend on querystrings and can rewrite the path in a nice URL.

How to Add a New Feed to WordPress

Within your theme or (highly recommended) child theme’s functions.php file, you’ll want to add the new feed and tell WordPress how you’re going to build it. One note on this… it will publish the new feed at https://yoursite.com/?feed=podcast

function add_podcast_feed() {
    add_feed( 'podcast', 'render_podcast_feed' );
}
add_action( 'init', 'add_podcast_feed' );

Retrieve an External Podcast Feed and Publish It In A WordPress Feed

We told WordPress we’d render the podcast using render_podcast_feed, so we now want to retrieve the external feed (designated as https://yourexternalpodcast.com/feed/ in the below function and duplicate it within WordPress at the time of the request. One note… WordPress will cache the response.

function render_podcast_feed() {
    header( 'Content-Type: application/rss+xml' );
    $podcast = 'https://yourexternalpodcast.com/feed/';
    
    $response = wp_remote_get( $podcast );
        try {
            $podcast_feed = $response['body'];

        } catch ( Exception $ex ) {
            $podcast_feed = null;
        } // end try/catch
 
    echo $podcast_feed;
} 

Rewrite Your New Feed to a Nice URL

Here’s a little bit of a bonus. Remember how the feed is published with a querystring? We can add a rewrite rule to functions.php to swap that out with a nice URL:

function podcast_feed_rewrite( $wp_rewrite ) {
    $feed_rules = array(
        'feed/podcast/' => 'index.php?feed=podcast'
    );

    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
add_filter( 'generate_rewrite_rules', 'podcast_feed_rewrite' );

Now, the new feed is published at https://yoursite.com/feed/podcast/

Add a Link to the Feed In Your Head

The last step is that you want to add a link within the head tags of your WordPress site so that crawlers can find it. In this case, we even want to designate the feed as the first one listed (above the blog and comment feeds), so we add a priority of 1. You’ll also want to update the title in the link and make sure it doesn’t match another feed’s title on the site:

function add_podcast_link_head() {
    $podcast_link = site_url().'/feed/podcast/';
    ?>
    <link rel="alternate" type="application/rss+xml" title="My Podcast Name" href="<?php echo $podcast_link; ?>"/>
    <?php
}
add_action('wp_head', 'add_podcast_link_head', 1);

Your New WordPress Podcast Feed

The nice thing about this method is that we were able to self-contain all of the changes within the site theme… no additional template files or editing of headers, etc. A couple of important details:

  • Permalinks – Once you add the code to functions.php, you’ll need to open Settings > Permalinks in WordPress admin. That will refresh your permalink rules so that the code we added for the rewrite is now implemented.
  • Security – If your site is SSL and your podcast feed is not, you’re going to run into issues with mixed security. I’d highly recommend ensuring both your site and your podcast hosting is securely hosted (at an https address with no errors).
  • Syndication – I would highly recommend using this domain-specific podcast feed to syndicate out to Google, Apple, Spotify and any other service. The advantage here is that you can now change your podcast host whenever you’d like and won’t have to update each service’s source feed.
  • Analytics – I’d personally recommend having a service like FeedPress where you can customize your feed and get some centralized tracking on it’s use beyond what many services provide. FeedPress also allows you to automate publishing to your social channels, a very cool feature!

Want to see if it’s working? You can use the Cast Feed Validator to verify the feed!

This site uses Akismet to reduce spam. Learn how your comment data is processed.