How to display post images in WordPress RSS feed

wp feed image
By default WordPress RSS feeds show only text content. You can show images from post into your RSS feed.
Edit the functions.php file in your theme and put the following lines.

To show thumbnail images:

function show_image_feed($content) {

global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
);

$attachment = get_posts($args);

if ($attachment) {

 $content =  '

' . wp_get_attachment_image($attachment[0]->ID, 'thumbnail') . '

' . $content . 'Read Complete post.'; } return $content; } add_filter('the_excerpt_rss', 'show_image_feed'); // for feed excerpts add_filter('the_content_feed', 'show_image_feed');

 

To show medium sized images:

function show_image_feed($content) {

global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
);

$attachment = get_posts($args);

if ($attachment) {

 $content =  '

' . wp_get_attachment_image($attachment[0]->ID, 'medium') . '

' . $content . 'Read Complete post.'; } return $content; } add_filter('the_excerpt_rss', 'show_image_feed'); // for feed excerpts add_filter('the_content_feed', 'show_image_feed');

 

To show full size images:

function show_image_feed($content) {

global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
);

$attachment = get_posts($args);

if ($attachment) {

 $content =  '

' . wp_get_attachment_image($attachment[0]->ID, 'full') . '

' . $content . 'Read Complete post.'; } return $content; } add_filter('the_excerpt_rss', 'show_image_feed'); // for feed excerpts add_filter('the_content_feed', 'show_image_feed');

Subscribe to My Newsletter
Receive all new posts and site updates in your mailbox.
Name:
Email:
 
Powered by Optin Form Adder

Tags: , , , ,

4 Responses to "How to display post images in WordPress RSS feed"

  • Subir says:
    • Puneet says:
  • Subir says:
    • Puneet says:
Leave a Comment