WordPress

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 ^

Join Paulund

  • Get access to 100s of premium tutorials and downloadable content
  • Members content consists of Premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • Priority email development support
  • No ads

Here at Paulund you'll find Web Development tutorials and snippets focusing mainly on PHP, WordPress and CSS. Members will get access to premium tutorials that go into more detail about development with these languages. You will also get access to downloadable premium content based on the tutorial.

Join Paulund

Leave a Reply

Your email address will not be published. Required fields are marked *