Add featured image to feed BEFORE excerpt

I’m making a feed for a newsletter. The content of feed must to have a rich text excerpt and a featured image. This hook seems to work:

function add_feed_content($content) {
if(is_feed() && ‘newsletter’ === get_query_var( ‘tag’ )) {
global $post;
if (has_post_thumbnail( $post->ID )) {
$content = get_the_post_thumbnail( $post->ID, ‘large’);
} else {
$content = ”;
}
$content .= the_excerpt();
}
return $content;
}
add_filter(‘the_excerpt_rss’, ‘add_feed_content’);

But featured image appears AFTER excerpt, regardless of what I put first in $content. Why? How can I insert the image first?

Here can be seen the feed in action: https://raquelfriera.e451.net/tag/newsletter/feed/

Read more here:: Add featured image to feed BEFORE excerpt

Leave a Reply

Your email address will not be published. Required fields are marked *