Skip to content

Instantly share code, notes, and snippets.

@graylaurenm
Created August 10, 2014 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graylaurenm/668d9654754f2e504fb1 to your computer and use it in GitHub Desktop.
Save graylaurenm/668d9654754f2e504fb1 to your computer and use it in GitHub Desktop.
Add Images to RSS
/*
* Use to insert images into your RSS content. Good for use with Feedburner.
*/
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'large', array( 'style' => 'display: block; max-width: 100%; height: auto; margin: 10px 0;' ) ) . '' . $content;
}
return $content;
}
/*
* Use to insert images into your RSS feed. Good for use with MailChimp.
*/
add_action('rss2_ns', 'lgd_yahoo_media_tag');
function lgd_yahoo_media_tag(){
echo 'xmlns:media="http://search.yahoo.com/mrss/"';
}
add_action('rss_item', 'lgd_rss_featured_image', 20);
add_action('rss2_item', 'lgd_rss_featured_image', 20);
function lgd_rss_featured_image($content) {
if( get_the_post_thumbnail() ) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
echo '<media:content url="' . $image[0] . '" medium="image" width="100%" height="auto" />';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment