How to add featured image or custom field to xml feed?

The RSS2 feed is generated in the wp-includes/feed-rss2.php file. In this file, there is an action hook named rss2_item. You can use this action hook to add tags to each item in your feed.

There is a codex article on rss2_item with examples, including this one for adding an <image> tag:

<?php
add_action('rss2_item', 'add_my_rss_node');

function add_my_rss_node() {
    global $post;
    if(has_post_thumbnail($post->ID)):
        $thumbnail = get_attachment_link(get_post_thumbnail_id($post->ID));
        echo("<image>{$thumbnail}</image>");
    endif;
}
?>

Leave a Comment