Content Marketing

WordPress: How To Build a Custom Feed In Your Site For Your Externally Hosted Podcast

Podcasts have exploded in growth and continue to be the go-to medium for many people—some of them are your target audience. Podcast hosting is highly encouraged because its infrastructure delivers these large audio files much more efficiently than the average host server. It also offers meta information, transcription, custom analytics, and several other features integral to podcasts… especially RSS feeds. Feeds are critical since syndication to popular podcast sites and mobile applications is essential for building your audience.

Many years ago, I hosted a popular marketing podcast for several years on a podcast host. My RSS feed had to point to their domain, and they didn’t have any custom domain functionality. They also weren’t updating their platform with newer features or integration opportunities. So, after several years, I was forced to migrate to a new podcast host. I lost thousands of listeners because so much of my audience was subscribed via their domain URL.

Hindsight is 20/20, of course, but what I should have done was republish their feed through my website, which is built on WordPress. This isn’t difficult to do; it’s just three steps using your child theme’s functions.php file:

  1. Add a new feed.
  2. Copy the contents of their feed into your own.
  3. Rewrite your feed URL to a nice URL rather than using the querystring in step 1.

One important note on this… WordPress caches feeds, so if you’re testing and not seeing any changes, you’ll need to modify your querystring like &cache_buster=1. This will force WordPress to generate a fresh feed.

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 will 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.

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 could self-contain all of the changes within the site theme… no additional template files or editing of headers, etc. A couple of essential details:

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

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

Appreciate this content?

Sign up for our weekly newsletter, which delivers our latest posts every Monday morning.

We don’t spam! Read our privacy policy for more info.

Douglas Karr

Douglas Karr is CMO of OpenINSIGHTS and the founder of the Martech Zone. Douglas has helped dozens of successful MarTech startups, has assisted in the due diligence of over $5 bil in Martech acquisitions and investments, and continues to assist companies in implementing and automating their sales and marketing strategies. Douglas is an internationally recognized digital transformation and MarTech expert and speaker. Douglas is also a published author of a Dummie's guide and a business leadership book.

Related Articles

Back to top button
Close

Adblock Detected

Martech Zone is able to provide you this content at no cost because we monetize our site through ad revenue, affiliate links, and sponsorships. We would appreciate if you would remove your ad blocker as you view our site.