5
votes

After having spent hours and tried all different functions and plugins, I would like to ask if one of you already succeeded in adding a new tag in his RSS feed for the featured image.

Both with the plugins and the functions I tried, the image went directly in the description tag, right before the description text that I also need to fetch.

Here is one of the function I tried :

function insertThumbnailRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '' . $content;
}
return $content;
}

add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');

Any ideas or suggestions?

I am fetching the RSS feed of my blog using Yahoo API.

Thanks for help.

1

1 Answers

0
votes

This can be easily done with the following code added to your theme functions.php file:

function add_rss_item_image() {
    global $post;
    if(has_post_thumbnail($post->ID))
    {
        $thumbnail = get_attachment_link(get_post_thumbnail_id($post->ID));
        echo"\t<image>{$thumbnail}</image>\n";
    }
}

add_action('rss2_item', 'add_rss_item_image');
add_action('rss_item', 'add_rss_item_image');

You can use the same method to output a custom field value in your feeds.

Good luck!