# Featured Images as media:content in RSS

> Adds each post's featured image to the RSS feed as a media:content element, the format email newsletter tools and feed readers use to show a thumbnail.

- Type: PHP
- Runs: Run everywhere
- Category: [RSS Feeds](https://wpide.com/library/category/rss/)
- Tags: rss, images, newsletter
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/featured-image-as-media-content/

## Code

```php
// Image size used in the feed.
$wpide_feed_image_size = 'large';

add_action( 'rss2_ns', function () {
    echo 'xmlns:media="http://search.yahoo.com/mrss/"' . "\n";
} );

add_action( 'rss2_item', function () use ( $wpide_feed_image_size ) {
    $post = get_post();

    if ( ! $post || ! has_post_thumbnail( $post ) ) {
        return;
    }

    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post ), $wpide_feed_image_size );

    if ( ! $image ) {
        return;
    }

    $mime = get_post_mime_type( get_post_thumbnail_id( $post ) );

    printf(
        "<media:content url=\"%s\" medium=\"image\" width=\"%d\" height=\"%d\"%s />\n",
        esc_url( $image[0] ),
        (int) $image[1],
        (int) $image[2],
        $mime ? ' type="' . esc_attr( $mime ) . '"' : ''
    );
} );
```

## Notes

Mailchimp, Feedly and most RSS-to-email services read this element. The image size is set at the top.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Featured Images as media:content in RSS" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
