Support » Alpha/Beta/RC » Adding support for the_post_thumbnail in RSS Feeds

  • Originally posted here: http://cdharrison.com/2009/12/the_post_thumbnail-for-rss-feeds/

    the_post_thumbnail is one of my favorite additions to WordPress 2.9, but I recently ran into a problem… the images I had set as my post thumbnails weren’t being included in my RSS feed. Assuming you’ve already added support for thumbnails to your theme, you should be able to add this snippet to your theme’s functions.php file to display them along with your content:

    function insertThumbnailRSS($content) {
        $content = '<p>' .the_post_thumbnail('medium'). '</p>' .$content;
        return $content;
    }
    
    add_filter('the_excerpt_rss', 'insertThumbnailRSS');
    add_filter('the_content_rss', 'insertThumbnailRSS');

    Thanks to Dougal Campbell for pointing me in the right direction!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I wasn’t aware the_content_rss was being deprecated in 2.9. Here’s an updated snippet:

    function insertThumbnailRSS($content) {
        $content = '<p>' .the_post_thumbnail('medium'). '</p>' .$content;
        return $content;
    }
    
    add_filter('the_excerpt_rss', 'insertThumbnailRSS');
    add_filter('the_content_feed', 'insertThumbnailRSS');

    There may be better way of doing this – see http://cdharrison.com/2009/12/the_post_thumbnail-for-rss-feeds/#comment-15583 , but it broke when I tried to implement it. If anyone has a better idea, I’d love to hear it.

    (I’m running WordPress 2.9 Release Candidate 1.)

    A better approach:

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

    Special thanks to: Sébastien Méric

    This is exactly what I was looking for. Inserting the medium sized the_post_thumbnail (if there is one for the post) in the feed.

    Last snippet just spits Warning: Cannot modify header information - headers already sent by (output started at functions.php:3) in feed-rss2.php on line 8 right back at me though. 🙁

    Ideas?

    EDIT: Yes, I used Sébastien’s full snippet from http://cdharrison.com/2009/12/the_post_thumbnail-for-rss-feeds/ , no workie. WP v2.9 stable btw.

    Actually, it works. It was an error on my side.

    This didn’t work for me. Any ideas?

    @giant slayer – One of the issues I noticed with this approach is that it requires the feed be accessed at /feed/rss/

    Are you getting any particular errors? What version of WordPress are you running?

    (Sorry for delay in responding. I should have sub’d to the RSS fee for this thread.)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding support for the_post_thumbnail in RSS Feeds’ is closed to new replies.