WordPress.org

Ready to get started?Download WordPress

Forums

Adding support for the_post_thumbnail in RSS Feeds (7 posts)

  1. Chris Harrison
    Member
    Posted 4 years ago #

    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!

  2. Chris Harrison
    Member
    Posted 4 years ago #

    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.)

  3. Chris Harrison
    Member
    Posted 4 years ago #

    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

  4. whiteout
    Member
    Posted 4 years ago #

    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.

  5. whiteout
    Member
    Posted 4 years ago #

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

  6. giant slayer
    Member
    Posted 4 years ago #

    This didn't work for me. Any ideas?

  7. Chris Harrison
    Member
    Posted 3 years ago #

    @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.)

Topic Closed

This topic has been closed to new replies.

About this Topic