Site icon RapidSpike

Featured Image In RSS Feed – WordPress

There are some great plugins and code examples out there for adding the featured image to the WordPress RSS feed. Unfortunately all the ones I found just add an <img> tag into the <description> tag of the feed, forcing anything that consumes the feed to use the image and the styling added:

<item>
<title>Synthetic User Journey Monitoring vs Uptime Monitoring</title>
<link>https://www.rapidspike.com/blog/user-journey-vs-uptime/</link>
<description><![CDATA[<p><img src="https://www.rapidspike.com/wp-content/uploads/2016/06/blog-cover-image_ujvuptime-700x356.jpg" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" style="float:left; margin:0 15px 15px 0;" />In this post we discuss the differences between user journey and uptime monitoring services - and why you probably need both...</p>
]]></description>
...
</item>

Here you can see the <img> tag is injected into the description. But what if you don’t want to display the image for every post? What if you don’t want images displayed on mobile browsers?

Instead, you can use rss2_item hook to update each feed item and add a new tag that contains just the featured image URL. Here’s a small update we made to our WordPress theme function.php file, giving anything consuming your feed complete control over how the image is used.:

Any script that consumes the feed can now chose when and how to use the featured image as the image path is now available separately from the <description> tag in the <featured_image> tag:

<item>
<title>Synthetic User Journey Monitoring vs Uptime Monitoring</title>
<link>https://www.rapidspike.com/blog/user-journey-vs-uptime/</link>
<description><![CDATA[<p>In this post we discuss the differences between user journey and uptime monitoring services - and why you probably need both...</p>
]]></description>
<featured_image>https://www.rapidspike.com/wp-content/uploads/2016/06/blog-cover-image_ujvuptime-700x356.jpg</featured_image>
...
</item>
Exit mobile version