Post

How to make your WordPress Featured Image appear in your RSS Feed

add the featured image inside your rss feed in wordpressAfter experiencing social media and how web sharing works, I understood that images are very important for the promotion of blog posts. Having been using WordPress for quite some time, I’ve seen that Featured Images are a great way to make an image appear differently on the main page and inside the post page and by using thumbnails you can have both worlds; beautiful and small thumbnails on the main page and a full image inside the post.

One problem that this has created though, is that WordPress by default does not show the Featured Post image inside your blog’s RSS feed. By adding the hook code below in functions.php of your theme, the post thumbnail will appear on the feed:

function custom_content_feed($content) {
    return wp_get_attachment_image(get_post_thumbnail_id(), 'full') . '<br />' . $content;
}
add_filter('the_content_feed', 'custom_content_feed');

If you would like the post thumbnail to be shown below the content, just change the second line to:

    return  $content . '<br />' . wp_get_attachment_image(get_post_thumbnail_id(), 'full');

Moreover, if an alternative image size is required, you can define it in the second parameter, e.g. replacing ‘full’ with ‘thumb’.

Of course, the wp_get_attachment_image documentation is available.

It’s actually easy to modify WordPress with just a few lines of code. More “WordPress Hacks” coming soon!



Nikolaos Anastopoulos has written 5 articles for Moneytized

Nikos is an IT consultant providing professional services with broad experience on data analysis, data migration and web development. Being part of the Moneytized team, Nikos migrates his expertise on Information Technology with Internet marketing, resulting in high quality Internet implementations. More on his profile.

  • Thank you – this worked perfectly!
    Jessica recently posted..Henry’s First Website

    Jessica

    January 6, 2012

  • Glad I could help.

    Angel

    January 13, 2012

  • Thank you so much! Worked great :) Now images will be displayed on my facebook page! :)
    Setyoufree recently posted..Radioactive water leaks at Japan nuclear plant

    Setyoufree

    March 19, 2012

  • Glad you liked it! :)

    Angel

    March 20, 2012

  • thanks Nik !
    is there a way to set an default image, if there is no featured image?

    ethan

    June 11, 2012

  • Hi, ethan!

    If there is no featured image the wp_get_attachment_image function will return an empty string and so you may replace the code as:

    function custom_content_feed($content) {
        $thumb = wp_get_attachment_image(get_post_thumbnail_id(), 'full');
        return ($thumb != '' ? $thumb : '<img src="/your/default/image/path.ext" />') . '<br />' . $content;
    }
    add_filter('the_content_feed', 'custom_content_feed');
    

    I haven’t tested it but it should work…

    Nikolaos Anastopoulos

    June 11, 2012

Leave a comment  

name*

email*

website

Submit comment

CommentLuv badge
Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X