I try to avoid using plugins as much as possible. And the fairly simple process of adding an image to my RSS feed is something I wanted to share with you to help you avoid this.

Even the best plugins can fall victim to security flaws and be an additional security risk. Also, some plugins can conflict with each other and the more plugins you have, the more resources your site will need through increased HTTP and database requests. You also don’t get those nagging “Go Pro!” notifications, the fear of updating a plugin that might break your site or some funky new menu item in WordPress.

The code below will allow you to use your featured image in your vanilla RSS feed…which can then be part of your RSS MailChimp (or other RSS campaign).

Assumptions

  • You want to use your “featured image” as the image in your RSS feed.
  • You have access to your “functions.php” file in your child theme or theme you’re created.
  • You have a “medium” image size under “Settings” > “Media” that’s sized somewhere between 600-1000 pixels wide (for best results). You can also add your own specific image size just for this if you’d like.
  • You want the image to be linked to the post (permalink).
  • You haven’t done anything screwy with your RSS feed that would prevent this from working.
function featured_image_in_rss_feed( $content ) {
  global $post;
  if( has_post_thumbnail( $post->ID ) ) {
      $content = '<p><a href="' .get_permalink() . '">' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'max-width: 100%; height: auto;' ) ) . '</a></p>' . $content;
  }
  return $content;
}
add_filter( 'the_excerpt_rss', 'featured_image_in_rss_feed' );
add_filter( 'the_content_feed', 'featured_image_in_rss_feed' );

Important Tips

  • If you’re using your RSS feed to send emails, always send test your emails to various email clients.
  • It’s always best not to cache your feed.
  • If you have image hotlinking enabled, be sure your site is not blocking image requests that do not have the referrer domain set in the request header.
  • ALL content on your site should be served via HTTPS and not be mixed content.
  • If you’re using a CDN, change the double slash “//” at the start of CDN CNAME you are given to “https://” to ensure images are displayed properly. The reason you are given just the “//” is to support mixed content (see the point above).

Resources