Feedspor Internet Solutions

How to Add Featured Images to Your WordPress RSS Feed

7 de agosto de 20268 min de leituraFeeds RSS
How to Add Featured Images to Your WordPress RSS Feed

Short answer: WordPress does not include featured images in its RSS feed by default, so many readers and tools show your posts without a picture. You can fix it in three ways: insert the image at the top of the feed content, add a media:content or media:thumbnail tag, or add an enclosure. The most compatible approach is to do both the first and the second, using a large image size and full, absolute URLs.

Images make a big difference in feed readers, news apps, email digests and social posting tools. A post with a thumbnail stands out in a list; a post without one looks unfinished or gets a random image scraped from the page. Yet the default WordPress feed only includes images that happen to be inside the post body, and only when the feed shows full text. This guide explains why, what the options are, and how to implement them without breaking the feed.

Why WordPress leaves featured images out

WordPress’s feed templates were written before featured images, officially “post thumbnails”, became standard in themes. The feed outputs the post title, link, date, categories, excerpt and, if you choose full text, the post content. The featured image is stored separately as post metadata, so it is not part of either.

The practical result:

Some SEO plugins and themes add featured images to feeds as a setting, so check your plugin options before writing any code. If none does, the methods below are straightforward.

How apps look for an image in a feed

There is no single official “image” element for RSS items, so different apps look in different places. Most check several, in roughly this order:

Where the image is Example Who reads it
Media RSS tag media:content or media:thumbnail Many readers, aggregators and automation tools
Enclosure enclosure with an image MIME type Some readers and tools; podcasts use it for audio
First image in content An img tag in content:encoded or description Almost every reader as a fallback
The web page itself og:image on the linked page Some apps and social tools, if nothing is in the feed

Because behaviour differs, the safest plan is to provide the image in more than one place: a Media RSS tag for apps that look for structured data, and an image at the top of the content for everything else.

Method 1: add the image to the feed content

This method puts the featured image at the top of each item’s excerpt and content, but only in the feed, not on your website. A short snippet in a child theme’s functions.php or a small custom plugin does it:

function feed_add_featured_image( $content ) {
    if ( is_feed() && has_post_thumbnail() ) {
        $img = get_the_post_thumbnail( null, 'large', array( 'style' => 'max-width:100%;height:auto;' ) );
        $content = '<p>' . $img . '</p>' . $content;
    }
    return $content;
}
add_filter( 'the_excerpt_rss', 'feed_add_featured_image' );
add_filter( 'the_content_feed', 'feed_add_featured_image' );

Notes on this approach:

Method 2: add a Media RSS tag

Media RSS is a widely used extension for describing images, audio and video in feeds. Adding it takes two small steps: declare the namespace on the feed, and output a tag inside each item.

add_action( 'rss2_ns', function () {
    echo 'xmlns:media="http://search.yahoo.com/mrss/" ';
} );
add_action( 'rss2_item', function () {
    if ( ! has_post_thumbnail() ) return;
    $id  = get_post_thumbnail_id();
    $src = wp_get_attachment_image_src( $id, 'large' );
    if ( ! $src ) return;
    printf( '<media:content url="%s" medium="image" width="%d" height="%d" />' . "\n",
        esc_url( $src[0] ), (int) $src[1], (int) $src[2] );
} );

This gives apps a clean, structured image without them having to parse your HTML. Some plugins already declare the Media RSS namespace; declaring it twice makes the feed invalid, so check the feed’s opening rss tag after adding the code.

Method 3: use an enclosure

An enclosure tag attaches a file to an item and requires the file’s URL, size in bytes and MIME type. It is the standard for podcasts, and some readers display image enclosures as thumbnails. There are two drawbacks. First, RSS 2.0 allows only one enclosure per item, so if you ever attach audio, the image competes with it. Second, you must provide the correct file length; a wrong value is a validation error. For most blogs, Media RSS plus an image in the content is simpler and more widely used.

Choosing the right image size and format

Feed images travel to many places: reader lists, full-screen article views, email digests and social posts. A few rules keep them looking good everywhere:

Testing the result properly

Do not trust a single view. Test in this order:

  1. View the raw feed at /feed/ and check that each item has the image tag or the image at the top of the content, with an absolute HTTPS URL.
  2. Validate the feed with the W3C Feed Validation Service to catch duplicate namespaces or malformed tags.
  3. Add the feed to two different readers, ideally one web-based and one mobile app, and check thumbnails in the list view and images in the article view.
  4. Check any tool that uses your feed, such as an email platform or social posting tool, with a fresh post. Many tools cache old items and will not reprocess them.
  5. Purge caches if nothing changes, since feed caching often hides the new output.

Common mistakes to avoid

When the source is not your site

If you follow or reuse feeds from other sites that come without images, you cannot change their WordPress settings. Our tool, Feeds, reads a site’s items with titles, images, summaries and dates, using the existing feed and the page’s structured article data where available, and shows you a preview of exactly what it found before you create the feed. It works from the outside, with no plugin on the source site. See how it works on the home page.

Related reading

The bottom line

WordPress leaves featured images out of its feeds, but adding them is a small change with a visible payoff in every reader and tool that uses your feed. Put a large image at the top of the feed content for universal support, add a Media RSS tag for apps that look for structured images, use absolute HTTPS URLs, and test in more than one reader. Your posts will look finished wherever they appear.

FAQ

Does the WordPress RSS feed include featured images?

Not by default. The feed includes images that are inside the post body when it shows full text, but the separately stored featured image is left out unless a theme, plugin or snippet adds it.

What is the best way to add images to an RSS feed?

Use two methods together: place the image at the top of the feed content, and add a media:content tag from the Media RSS namespace. This covers both apps that parse HTML and apps that look for structured media tags.

Why are my feed images blurry?

The feed probably uses a small image size such as the 150-pixel thumbnail. Switch to the large size or a custom size at least about 1200 pixels wide.

Why don’t images show in my RSS reader even though they are in the feed?

Check that the image URLs are absolute and use HTTPS, and that a lazy-loading plugin has not replaced them with placeholders. Also note that readers do not re-fetch old items, so test with a new post.

Can I use an enclosure for images?

You can, and some readers display it, but RSS 2.0 allows only one enclosure per item and requires the exact file size. For most blogs, Media RSS plus an image in the content is simpler.

#Feed formats#Publishing#RSS#WordPress
Crie seu primeiro feed — grátis.Um feed de qualquer página. Cada produto em cada catálogo.
Comece grátis
Internet Solutions

Mais da nossa equipe

Feitas pela Internet Solutions. Experimente nossos outros produtos — cada um economiza seu tempo de um jeito diferente.

internet-solutions.net ↗
Feeds
Visão geral de privacidade

Este site usa cookies para oferecer a melhor experiência de usuário possível. As informações dos cookies ficam armazenadas no seu navegador e servem para, por exemplo, reconhecer você quando volta ao nosso site e ajudar nossa equipe a entender quais seções do site você acha mais interessantes e úteis.