graylaurenm
8/10/2014 - 2:02 PM

Add Images to RSS

Add Images to RSS

/*
 * 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" />';
	}
}
/*
 * 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;
}