1

I'm using my own theme for a blog. In my functions.php file I added a function:

function featuredImageToRSS($content)
{
    global $post;
    if (has_post_thumbnail($post->ID)) {
        $content = '<image>' . get_the_post_thumbnail_url($post->ID) . '</image>' . $content;
    }
    return $content;
}

And used the following filters to apply it to the feeds:

add_filter('the_excerpt_rss', 'featuredImageToRSS');
add_filter('the_content_feed', 'featuredImageToRSS');

However those are not called in the atom feed (http://example.com/feed/atom/).

1

Actually I should have used the atom_entry() hook.

So the following code will add your post thumbnail to your atom feed:

function featuredImageToRSS()
{
    global $post;
    $content = '<image>';
    if (has_post_thumbnail($post->ID)) {
        $content .= get_the_post_thumbnail_url($post->ID);
    }
    $content .= '</image>';
    echo $content;
}


add_action('atom_entry', 'featuredImageToRSS');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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