Wednesday, December 16th, 2009
Post Thumbnails in 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 the rest of your feed content:
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');
Thanks to Dougal Campbell for pointing me in the right direction!
Thanks to Sébastien Méric here’s an event 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;
}
add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');
This item was posted by .
Tags:
Categories:
You can follow comments on this item via the RSS 2.0feed.
Comments are closed.