Created
August 10, 2014 14:02
-
-
Save graylaurenm/668d9654754f2e504fb1 to your computer and use it in GitHub Desktop.
Add Images to RSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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