Podcast Feed

Since my site has weekly MP3 uploads, it makes sense to create a podcast feed for it. Unfortunately, those updates were implemented with custom post types, which don’t generate podcast feeds automatically with the <enclosure> tags. Thus I would have to generate a custom feed myself.

The Codex page on Customizing Feeds explains how to get a custom post type to use my own custom feed. Since I’m using a child theme, I used get_stylesheet_directory() instead of get_template_directory().

When I first setup the custom post type and imported the existing content, the meta value _wp_attached_file included the full URL. It still does as the custom insert post functions for the custom post type have been written that way. Thus to generate the path to the file (to get the filesize for the RSS feed), I had to modify the output of get_attached_file() by using the get_attached_file filter.

Using the default RSS2 template as a starting point, I modified the template to produce a feed which more or less follows the iTunes format. The major challenge was getting the filesize of the MP3 files, this was done with the PHP filesize() function.

$size = filesize( get_attached_file( $child->ID ) );

The author and subtitle fields were field with the available post meta stored with the custom post type.

A strange problem I encountered was that this worked perfectly with iTunes on my test setup, but iTunes refused to recognize the feed properly on the live site. This was solved by using feedburner, and subscribing to the feedburner feed instead. However, this still doesn’t explain what’s wrong with the feed on the actual site which prevents iTunes from getting it properly.


7 thoughts on “Podcast Feed”

  1. When you modify the RSS template in WordPress, does this affect all posts? For example, what if a post wasn’t part of a podcast? Would this somehow mess with the output of a regular post?

    Upon the next upgrade of WP, wouldn’t this overwrite the changes you made to the RSS template?

    I’m also creating a website for my Church, and am trying to get the podcast to work (with a custom post type and custom fields). 🙂

    1. Hi Adam,

      I encourage you to read the Codex page on customizing feeds my post links to. The sample code there shows how you can control which RSS template gets called.

      I made the changes in a child theme, so no my changes will not be overwritten by WordPress or theme upgrades. You shouldn’t be modifying WordPress core files, or theme files, directly anyway.

      1. Thanks for your response. I didn’t realize one could make a template for a feed! That’s really cool. I’ll see if I can get this working…

      2. Hi fonglh,

        The template doesn’t work. I followed the instructions exactly, but the MP3 file was never picked up and linked to from my custom post type. Did you use a CPT for the sermons in your Church’s website? Maybe that’s the issue… I shouldn’t use a CPT?

      3. Yes I’m using a CPT, it works fine. You have to customize the template to get the MP3 info. It doesn’t happen by magic.

      4. Thanks very much for your help in my process of setting up my Church’s Podcast. I appreciate your actually responding to your blog post comments! Seems like many people don’t. I’ve been researching off-and-on for a couple weeks (as this is a volunteer project), and have finally found an answer!

        I never got the template to work. What I wound up doing was using a function to add custom data from my custom fields to the feed. After that, I burnt the CPT feed URL with Feedburner, which took care of the enclosures for the MP3 files. It works like a charm, and there are no additional plugins! …just a Feedburner service added to the Google Account.

        By the way… what is your Church’s website? I’d love to see what things you incorporated into the site. The site I’m working on is still in the build stage, and the address is http://berean.baneydesign.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s