How to display Post Thumbnails in WordPress feeds [CODE]

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

When year ago I was working on new functions for e-art.lv, I decide to use Post Thumbnails In WordPress Feeds. There were several reasons why we (e-art.lv) started to use that “feature“. We saw that some of RSS aggregators are using these features from other RSS and Atom feeds.  We wanted them too… Here is my solution for post thumbnails in WordPress excerpt feeds.

Code of Post Thumbnails In WordPress Feeds

// Post thumbnails in RSS from Simple Media Code
// http://simplemediacode.info/?p=248 by http://Umbrovskis.com
function me3_rssthumbnails($content) {
global $post;
if (has_post_thumbnail($post->ID)){
$content = ''.get_the_post_thumbnail($post->ID,'medium',
array('align'=>'left','alt'=>$post->post_title))."n".$content;
}
return $content;
}
add_filter('the_excerpt_rss', 'me3_rssthumbnails');

Here comes code explanation:

we are taking existing content of RSS

me3_rssthumbnails($content)

we are taking uploaded image from post

has_post_thumbnail( $post->ID )) 

Here we are taking medium size image from post, aligning it to left, and taking post title as descriptional text in alt attribute.

$post->ID,'medium',array('align'=>'left','alt'=>$post->post_title)

Download as WordPress plugin

More info about used WordPress functions

  • http://codex.wordpress.org/Function_Reference/has_post_thumbnail
  • http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
  • http://codex.wordpress.org/Function_Reference/add_filter
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

When year ago I was working on new functions for e-art.lv, I decide to use Post Thumbnails In WordPress Feeds. There were several reasons why we (e-art.lv) started to use that “feature”. We saw that some of RSS aggregators are usign these features from other RSS and Atom feeds. We wanted them too… Here is my solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>