Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am able to add a post featured image to the RSS feed like so:

function insertThumbnailRSS($content) {
    global $post;
    if(has_post_thumbnail($post->ID)){
        $content = ''.get_the_post_thumbnail($post->ID, 'thumbnail', array('alt' => get_the_title(), 'title' => get_the_title(), 'style' => 'float:right;')).''.$content;
    }
    return $content;
}
add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');

However, upon examining the XML generated for the RSS feed, I noticed it sticks the featured image into the XML description item tag.

How can I insert post featured image into it's own RSS feed item tag of let's say "image", rather than just inserting it in with the post's content?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You could do it by adding an action to the hook 'rss2_item' like so:

add_action('rss2_item', function(){
  global $post;

  $output = '';
  $thumbnail_ID = get_post_thumbnail_id( $post->ID );
  $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumbnail');
  $output .= '<post-thumbnail>';
    $output .= '<url>'. $thumbnail[0] .'</url>';
    $output .= '<width>'. $thumbnail[1] .'</width>';
    $output .= '<height>'. $thumbnail[2] .'</height>';
    $output .= '</post-thumbnail>';

  echo $output;
});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.