Skip to content

Instantly share code, notes, and snippets.

@jlengstorf
Created March 8, 2013 22:20
Show Gist options
  • Save jlengstorf/5120378 to your computer and use it in GitHub Desktop.
Save jlengstorf/5120378 to your computer and use it in GitHub Desktop.
Adds iTunes podcasting tags to a WordPress RSS2 feed for post type "podcast"
<?php
/* BEGIN PODCASTING FILTER HOOKS */
function example_add_itunes_namespace( )
{
if (get_post_type()==='podcast') {
echo 'xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"';
}
}
function example_add_itunes_header_tags( )
{
if (get_post_type()!=='podcast') {
return;
}
// These could be set up as custom meta
$subtitle = 'Podcast subtitle goes here.';
$summary = 'Podcast summary goes here.';
$owner = array(
'name' => 'Podcast Owner',
'email' => '[email protected]',
);
$feed_img = 'http://www.example.org/path/to/podcast/image.jpg';
// DON'T FORGET TO UPDATE THE CATEGORIES BELOW
?>
<itunes:subtitle><?=$subtitle?></itunes:subtitle>
<itunes:author><?bloginfo('name')?></itunes:author>
<itunes:summary><?=$summary?></itunes:summary>
<itunes:owner>
<itunes:name><?=$owner['name']?></itunes:name>
<itunes:email><?=$owner['email']?></itunes:email>
</itunes:owner>
<itunes:image
href="<?=$feed_img?>" />
<itunes:category text="Category 1">
<itunes:category text="Subcategory 1" />
</itunes:category>
<itunes:category text="Category 2" />
<?php
}
function example_add_itunes_item_tags( )
{
if (get_post_type()!=='podcast') {
return;
}
global $post;
$item_img = 'http://www.example.org/path/to/podcast/image.jpg';
// Creates a crude excerpt
$excerpt_array = explode(' ', strip_tags($post->post_content));
$excerpt = $excerpt_array[0];
$count = count($excerpt_array);
$length = min(30, $count);
for ($i=1; $i<$length; $i++) {
$excerpt .= ' ' . $excerpt_array[$i];
}
$excerpt .= ' ' . preg_replace('/\W$/', '', $excerpt_array[$i]) . '...';
?>
<itunes:author><?bloginfo('name')?></itunes:author>
<itunes:summary><?=$excerpt?></itunes:summary>
<itunes:image
href="<?=$item_img?>" />
<?php
}
function example_setup_podcast()
{
add_action('rss2_ns', 'example_add_itunes_namespace');
add_action('rss2_head', 'example_add_itunes_header_tags');
add_action('rss2_item', 'example_add_itunes_item_tags');
}
add_action('after_setup_theme', 'example_setup_podcast');
/* END PODCASTING FILTER HOOKS */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment