Using Featured Images In Your RSS Excerpts

raw RSS feed data
mind numbing view of your RSS feed.

In the past few months, as I’ve been working on my Send Images to RSS plugin, I’ve spent a lot of time contemplating raw RSS feeds, which means I’ve spent a lot of time looking at screens that look like this (no bigger version available, as it’s not any better at a larger size, trust me!). My friend Jo of Callia Web asked me if my plugin worked for bloggers who are using excerpts for their RSS reading settings, which is a great question (belatedly addressed in the plugin documentation), and which I thought was worth exploring in a little more detail.

The short answer is no: if you are using excerpts for your RSS feed, my plugin is not for you. The Send Images to RSS plugin works only on the full content of the feed.

As of version 3.0, Send Images to RSS supports excerpts, and it’s pretty easy and awesome.

If you’re like my friends Kira and Michelle of Sunshine and Hurricanes and want to send just the excerpts of your posts in your feed–they do a weekly email to subscribers, but blog 3-5 times/week–then you’ll probably want your email to look more like this, which shows just the first bit of each post, along with the featured image:

how to use featured images in your RSS excerpts
Sunshine & Hurricenes weekly email

I mean, we all love pretty pictures, right? And they make any email more interesting. So let’s talk about how to use featured images in your RSS excerpts, even if you’re not sending your full content to your subscribers. This is a much easier issue to tackle than working with every single image in a post, and there are a lot of featured image/RSS plugins in the WordPress.org repository, if you look. One which I really like is “Add featured image to RSS feed” by Corey Salzano, because it’s very simple and to the point.

However, I have two issues, which aren’t necessarily unique to this plugin, as they’re issues I see around quite a lot:

  1. the plugin uses the large copy of the image for the feed, which is problematic for email solutions as the usual WordPress large image size is too big for most emails. Other featured image plugins may take a different approach and use the thumbnail or another size image.
  2. the filter is applied to the content in the feed, not just the excerpt. This means that if your feed is set to share the full content, but you’re wanting the featured image functionality for emails, blog subscribers who use a service like feedly will see the featured image both in your content and before it, which is probably not what you’re wanting, either.

I had actually not really considered the latter issue until just recently, since I (as well as others) have been going with the assumption that the feed content and excerpts are pretty much the same thing and should be targeted simultaneously, which isn’t actually true at all. They tackle different parts of your feed and you can–and should–make use of both!

Include Featured Images in your RSS Excerpts (DIY)

This function can be added to your theme’s functions.php file, or you can write your own little plugin, if you prefer. The key thing here is that you’re creating a filter, and hooking it only to the_excerpt_rss. The plugins I’ve looked at hook it not only to this, but also to the_content_feed. On the one hand, this is theoretically fine, since you want to make sure that your featured image is included with your feed no matter what, but if you’re using the full content for your main feed and finagling what is basically an excerpt view, then you’re sending out a duplicate image in your feed. For your purposes, the_excerpt_rss should be fine.

Corey’s plugin is the starting point for this snippet, since it was very simple and did exactly what I wanted.

<?php
// you can add this to your theme's functions.php file. do not include the opening tag.
add_filter( 'the_excerpt_rss', 'rgc_add_featured_image_to_feed_excerpt', 1000, 1 );
function rgc_add_featured_image_to_feed_excerpt( $content ) {
if ( has_post_thumbnail( get_the_ID() ) ) {
$content = get_the_post_thumbnail( get_the_ID(), 'thumbnail', array( 'align' => 'left', 'style' => 'margin-right:20px;' ) ) . $content;
}
return $content;
}
view raw functions.php hosted with ❤ by GitHub

Additionally, if you look through line 9 of this snippet, you’ll see that we’re opting to use the thumbnail sized version of the featured image, which is called with the get_the_post_thumbnail function. You can use any named size you like, but keep in mind that if you use a size larger than your email template, you’ll end up with blown up emails. The array in line 9 shows what attributes you’re assigning to your image; here, it’s 1) left alignment, and 2) adding a right-margin of 20px to the image so that it’s not crowded by the text. Note that these have to be added inline, since your CSS options are limited in emails.

Note: this snippet only works if you assign a featured image to your post. Even if you have images in the post, if one isn’t actually set as featured, it won’t be added to your excerpt/feed.

If you have your WordPress site set up to show just the summary of each post in your feed, you could stop here. the_excerpt_rss modifies the description in your RSS feed; the_content_feed modifies the content of your feed. So if you’re set up this way, your work is done and your RSS description includes some text and your featured image.

However, if you’re expecting that you have subscribers using an RSS feed reader service, who probably should have the full content of your feed, and you’re sending a digest type email where you want just the short version, you will want to take the next step and do some work in your email template. It’s also pretty simple. Here’s the template for Kira & Michelle (if your blog is just you, you could remove the author line if you like):

*|RSSITEMS:|*
<h2 class="mc-toc-title"><a href="*|RSSITEM:URL|*" target="_blank">*|RSSITEM:TITLE|*</a></h2>
<em>By *|RSSITEM:AUTHOR|*</em><br />
*|RSSITEM:CONTENT|*<br />
*|END:RSSITEMS|*
view raw mailchimp.txt hosted with ❤ by GitHub

MailChimp has a long page of all the possible RSS Merge Tags you could possibly want to use. I’ve kept theirs fairly simple, but feel free to experiment and add whatever you like to your own. At the top of that page, there are even preformatted tags, which handle everything for you in one line.

So there’s a start on using both your full content and making use of excerpts for your RSS feed, or for just optimizing your RSS feed excerpts.

Do something awesome. Tell a friend:

subscribe by email

If you're an email kind of person, that's totally cool. Go ahead and sign up here to get the latest blog entries in your inbox! No worries, I never share your address.
  • This field is for validation purposes and should be left unchanged.

Reader Interactions

Comments

  1. December 22, 2014

    Excellent post, Robin, and I use your plugin on several sites. This article just cleared up for me what to do with people who want to show an excerpt in their MailChimp emails but still want to use the featured image. I appreciate all of the time you spent starting into the heart of RSS. It is a daunting task!

  2. July 23, 2015

    This article was really helpful. I was kind of surprised there isn’t more written on this subject. If we wanted to name a different size what would we change? I’m happy with how the thumbnail looks in Mailchimp but in Bloglovin’ the image is way too small and pixelated. So I want to try “large”. Thank you!

    • July 23, 2015

      Nevermind. I changed it to ‘Medium’ so we’ll see how that looks in my next post on Bloglovin’. It looks good in Feedly. Large was too big in Mailchimp…

      • July 23, 2015

        Marina, I’m actually working on a significant release for my Send Images to RSS plugin which brings support for excerpts. It’s going to be pretty awesome, and will allow you to nicely tailor your excerpts and include the featured image, either as a thumbnail, medium size, or full width (custom to your email), with whatever alignment you want. At this point, it’s nearly finished, and I hope to release this in the next week or two. It will make excerpt only RSS feeds much easier.

  3. March 21, 2016

    I’m still having trouble with this & I’m hoping you can help. I put the following code into my Custom CSS & it is still not showing up in my MailChimp RSS email campaign.
    ‘left’, ‘style’ => ‘margin-right:20px;’ ) ) . $content;
    }
    return $content;
    }

    Am I doing something wrong? Thanks for your help 🙂 My website is http://www.honeysucklefootprints.com

    • March 21, 2016

      At least in the most recent post, your first image, the small one, already has the inline styles necessary to align it to the left. However, since it’s immediately followed by the first image in the post, which is a full width image, there is nothing obvious to show that it’s working correctly, even though it is. If you generally put your featured image into your post content, I would recommend not adding the featured image to the beginning of the post content in the feed.

      If you are wanting your emails to have only the excerpts and the featured image, you need to change that setting in your WordPress site under Settings > Reading, and change the “For each article in a feed, show” to Summary.

  4. July 30, 2016

    I think this is exactly what I’m looking for.. and It really is crazy that things aren’t just BUILT this way no?

    Could you explain to me if its possible.. how to use this on a Squarespace site?
    Is it just a code injection?

    • August 1, 2016

      I think it suits the original purpose of excerpts in RSS feeds–technology has advanced an awful lot and today we expect pretty pictures as a matter of course, but working with RSS feeds, I feel like it’s been around long enough that maybe it’s solving problems we no longer have, really.

      I’ve never worked with a Squarespace site, so I have no idea at all if something like this is possible there, but based on the little I know of the platform, I doubt that it is. The entire point of WordPress is to make every aspect of the codebase accessible and modifiable, so code like this is fairly easy to come up with and apply. I believe that Squarespace is intentionally more limited.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Bars Code Check chevron-down chevron-left chevron-right chevron-up Envelope Laptop Search Times Facebook GitHub Google Plus Instagram LinkedIn Pinterest Twitter WordPress Logo Wordpress Simple