29

Is there a way to send only an Image with a link and some alt text for each item in an RSS feed?

I looked at the enclosure tag but this is only for videos and music.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
sanders
  • 10,794
  • 27
  • 85
  • 127

9 Answers9

25

The enclosure element can be used to transmit pictures. The RSS 2.0 spec is quite clear about that, saying that the type is a MIME type. It does not say it is restricted to audio or video.

Here's an example: a set of photo feeds from Agence France Presse

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Dave Winer
  • 1,857
  • 1
  • 17
  • 13
  • 26
    It seems like current xml file in link doesn't have an enclosure. – trante Jul 26 '12 at 20:59
  • The former link does not have any enclosure example. Here's an example: [How do I show images in my RSS email?](https://help.activecampaign.com/hc/en-us/articles/115001387690-How-do-I-show-images-in-my-RSS-email-) – Franz Holzinger Mar 23 '21 at 09:40
13

One of solutions is to use CDATA in description

<![CDATA[
  Image inside RSS
  <img src="http://example.com/img/smiley.gif" alt="Smiley face">         
]> 

Note, that you may have a problem with hotlink prevented site.

frlan
  • 6,950
  • 3
  • 31
  • 72
Jeff_Alieffson
  • 2,672
  • 29
  • 34
12

This is possible in RRS2,

see http://cyber.law.harvard.edu/rss/rss.html#ltenclosuregtSubelementOfLtitemgt

So you have to use the enclosure tag, to add media

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
Barry de Graaff
  • 121
  • 1
  • 2
6

You should use the enclosure tag within item to include the image. You can use it for images by setting the correct Mime Type (for example: image/jpeg) and including the image size as the "length" attribute. The length attribute doesn't need to be completely accurate but it's required for the RSS to be considered valid.

Here's a helpful article that discusses this and other options.

Shez
  • 87
  • 1
  • 3
6

To work with the Mailchimp RSS to email feature, they expect the image to be specified in a <media:content> element inside <item>. This is their source for the feed item's image macro in their templates.

Thus, you need to add to the declarations

xmlns:media="http://search.yahoo.com/mrss/

Then inside the <item> element add

<media:content medium="image" url="http://whatever/foo.jpg" width="300" height="201" />

Without the extra declaration, the feed is invalid since media:content is not a known element.

vick
  • 179
  • 1
  • 9
  • I’ve done a [quick implementation for WordPress RSS feed](https://gist.github.com/jerome-rdlv/638869e1da0c3dba2bdc3973f6df7276). – Jérôme Nov 29 '21 at 10:58
1

Inside tag ITEM

<image:image xmlns:image="http://web.resource.org/rss/1.0/modules/image/">

http://domain. com/image.jpg < /image:image>

Inside Description Tag

<![CDATA[
    Some Text..
    <br/><img src='http://domain. com/image.jpg' ><br/>
    More Text
]]>
Muisca
  • 69
  • 1
  • 5
0

Regarding the <p> tag issue, You need to encode html within the xml.

Your code would look something like this:

<description>&lt;p&gt; Text in the tag &lt;/p&gt;</description>
Tony McCreath
  • 2,882
  • 1
  • 14
  • 21
0

Since you are using php you can use htmlentities() to encode the html tags. They look horrible in the xml but RSS readers know what to do with it.

http://php.net/manual/en/function.htmlentities.php

R.J. Steinert
  • 169
  • 1
  • 9
0

In rss 2.0 its as simple as adding an <image><url>...</url></image> tag:

https://validator.w3.org/feed/docs/rss2.html#ltimagegtSubelementOfLtchannelgt

<image> sub-element of <channel> *

<image> is an optional sub-element of <channel>, which contains three required and three optional sub-elements.

<url> is the URL of a GIF, JPEG or PNG image that represents the channel.

<title> describes the image, it's used in the ALT attribute of the HTML <img> tag when the channel is rendered in HTML.

<link> is the URL of the site, when the channel is rendered, the image is a link to the site. (Note, in practice the image <title> and <link> should have the same value as the channel's <title> and <link>.

Optional elements include <width> and <height>, numbers, indicating the width and height of the image in pixels. <description> contains text that is included in the TITLE attribute of the link formed around the image in the HTML rendering.

Maximum value for width is 144, default value is 88.

Maximum value for height is 400, default value is 31.

chovy
  • 72,281
  • 52
  • 227
  • 295