How to Add Featured Images to Your WordPress RSS Feed Using Functions.php

RSS feeds are a crucial tool for content distribution, especially for marketers looking to syndicate their blog posts, improve discoverability, or automate email newsletters. However, by default, WordPress does not include the featured image in RSS feeds, which can make your content less visually appealing when it appears in RSS readers or third-party platforms.

In this article, we’ll show you how to modify your WordPress RSS feed to include the post’s featured image after the title, using a simple snippet in your child theme’s functions.php file.

Why Add Featured Images to Your RSS Feed?

Including featured images in your RSS feed enhances the presentation of your content when syndicated on platforms like:

Without a featured image, your posts may appear plain and less engaging, reducing click-through rates and overall engagement.

How to Add Featured Images to Your RSS Feed in WordPress

To achieve this, we will modify the functions.php file of your child theme by using a WordPress filter that appends the featured image to the RSS feed’s post content. We recommend child themes over making the edit in a dependent theme that may be upgraded where you lose this functionality.

Step 1: Open Your Child Theme’s Functions.php File

  1. Log into your WordPress dashboard.
  2. Navigate to Appearance > Theme File Editor.
  3. In the right sidebar, locate and select functions.php.

Alternatively, you can edit this file via FTP or a file manager if you prefer direct file access.

Step 2: Insert the Following Code

function add_featured_image_to_rss($content) {
    global $post;

    if (has_post_thumbnail($post->ID)) {
        $thumbnail_url = get_the_post_thumbnail_url($post->ID, 'medium');
        $mime_type = get_post_mime_type(get_post_thumbnail_id($post->ID));

        $image_element = '<media:content url="' . esc_url($thumbnail_url) . '" medium="image" type="' . esc_attr($mime_type) . '" />';

        return $content . $image_element;
    }

    return $content;
}
add_filter('the_excerpt_rss', 'add_featured_image_to_rss');
add_filter('the_content_feed', 'add_featured_image_to_rss');

Step 3: Save the Changes

After pasting the code, click the Update File button to save the changes.

How This Code Works

Expected Outcome

Once implemented, your RSS feed will now contain the post’s featured image immediately after the title. It will look something like this in the raw XML feed:

<item>
    <title>Example Blog Post</title>
    <link>https://yourwebsite.com/example-post</link>
    <description>This is an example post content...</description>
    <media:content url="https://yourwebsite.com/wp-content/uploads/featured-image.jpg" medium="image" type="image/jpeg" />
</item>

Testing Your RSS Feed

After making these changes, you should verify that your RSS feed displays images correctly. You can check your feed by visiting:

https://yourwebsite.com/feed/?t=12

Feeds are agressively cached in WordPress, so add a querystring with a random number.

Final Thoughts

Adding featured images to your RSS feed is a simple yet powerful enhancement for marketers. It ensures that your content looks more appealing when shared across platforms, increasing engagement and visibility.

If you’re using your RSS feed for email automation, syndication, or social media sharing, this tweak can significantly improve how your content is presented to your audience.

Exit mobile version