Adding a featured image to atom feed

by FakeHeal   Last Updated May 16, 2018 12:08 PM

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 a (atom) feed. Only those that are RSS Feeds.

Tags : feed

Answers 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');
May 16, 2018 11:20 AM

Related Questions

RSS Feed cURL error 52?

Updated February 23, 2017 13:08 PM

Regarding Rss Feed Builder

Updated September 19, 2017 09:08 AM

Adding a second RSS feed

Updated June 02, 2015 23:03 PM