I am able to add a post featured image to the RSS feed like so:
function insertThumbnailRSS($content) {
global $post;
if(has_post_thumbnail($post->ID)){
$content = ''.get_the_post_thumbnail($post->ID, 'thumbnail', array('alt' => get_the_title(), 'title' => get_the_title(), 'style' => 'float:right;')).''.$content;
}
return $content;
}
add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');
However, upon examining the XML generated for the RSS feed, I noticed it sticks the featured image into the XML description item tag.
How can I insert post featured image into it’s own RSS feed item tag of let’s say “image”, rather than just inserting it in with the post’s content?
You could do it by adding an action to the hook ‘rss2_item’ like so:
Building off of codekipple’s great answer, here’s my modified implementation, which uses the valid Media RSS element
media:content
element (spec) and checking for the existence of a thumbnail/featured image:Note: Include the xmlns attribute here to make it validate. WordPress’s initial install doesn’t include that namespace declaration, and while you can change it, so can other themes/plugins.
More details on the other attributes etc. are in my non-WordPress-specific answer here.
This integrates with MailChimp’s RSS newsletter building.
Building off codekipple and D_N, I wanted a few more attributes in my
media:content
so here’s what I did:codekipple’s answer also actually adds the image below all feed content. I wanted my image above content, so I did this: