We earlier talked about setting a featured in WordPress and changing its dimensions. But WordPress, does not add this featured image into the RSS feeds. If you show featured image on your index pages, then you would surely like to add featured image to your RSS feeds.
Related Articles
The problem seems to be very big, but the solution is quite easy though. You need to add a little PHP code snippet to your theme’s functions.php file and that will do the trick. You can read our tutorial on editing functions.php file, if you don’t know it already.
Display Featured Image Before Post Content
// Adding Post Thumbnail To RSS Feeds
function add_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'add_post_thumbnail_feeds');
add_filter('the_content_feed', 'add_post_thumbnail_feeds');
Display Featured Image After Post Content
// Adding Post Thumbnail To RSS Feeds
function add_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<div>' . $content . get_the_post_thumbnail($post->ID) . '</div>';
}
return $content;
}
add_filter('the_excerpt_rss', 'add_post_thumbnail_feeds');
add_filter('the_content_feed', 'add_post_thumbnail_feeds');
Float The Image To The Left
// Adding Post Thumbnail To RSS Feeds
function add_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<div style="float:left; margin-right:5px;">' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'add_post_thumbnail_feeds');
add_filter('the_content_feed', 'add_post_thumbnail_feeds');
You can style the image and the content according to you. But make sure that your code is free of errors. An erroneous code in functions.php file can destroy your website completely.