RSS Feed

Add Current Post Image Thumbnail To RSS Feed In WordPress

In a previous post we went through how to add content after RSS feed in wordpress, now we can take this idea to add additional information to your RSS Feed. One thing about your RSS feed is that the user will not get to your information from your website, so if you have a post image thumbnail they will not see it from your RSS feed unless it is added to your post. So we can take the RSS hooks we learnt in the previous post and use this to add your post image thumbnail to the post.

Below is the code snippet which will get the current post id and then get the post image thumbnail for this current post and then uses the_excerpt_rss and the_content_rss hooks to add this into the RSS feed.

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
return $content;
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');
Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial