WordPress sites doesn’t show images in it’s RSS feeds by default. This is kept by WordPress so that XML RSS stays text version and easy to read. This way it also supports variety of RSS feed reader online and conforms to W3C standards.
However, you can easily show your article images in WordPress RSS feed of your site. You can either include whole article content or just the post excerpt. We will not be using any plugin and will edit Functions.php with manual code to do so.
This is how GeekAct.com/feed was looking without images prior to this tweak. Note that, there is no RSS Image Tag.
and this one is after addition of code,
It also passes the RSS validity test at W3C
Add Featured Image to RSS Feed without WordPress RSS feed plugin
This will involve editing the functions.php file of your theme. Like me, if you mostly use child themes or custom-functions.php or don’t change themes often this is best way as it avoids one more plugin.
Achieving Full RSS Feed with Images
Login to your WordPress site and go to “Appearance” and then “Editor”
Select your theme from the dropdown to be sure that you are editing correct theme and find functions.php or custom functions.php. Click on it.
Now, paste the below code at the end of your functions file and hit Save.
function rss_post_thumbnail($content) { global $post; if(has_post_thumbnail($post->ID)) { $content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_content(); } return $content; } add_filter('the_excerpt_rss', 'rss_post_thumbnail'); add_filter('the_content_feed', 'rss_post_thumbnail');
It would look something like below,
Now, check your WordPress feed at,
yousite.com/feed
Achieving Only Excerpt RSS Feed with Images
Not all people are fan of full RSS feeds. There are two reasons for that. One is, you might feel that readers might not visit your website if they are getting everything in feeds. Second one is to avoid scrapping by thieves and publishing to their site without your permission.
So, you can use the below optimized code in your functions.php. I like this one more due to option of image size selection. You can change that “medium” to “full”. Also, setting margins makes text little more readable in RSS readers.
function featuredtoRSS($content) { global $post; if ( has_post_thumbnail( $post->ID ) ){ $content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content; } return $content; } add_filter('the_excerpt_rss', 'featuredtoRSS'); add_filter('the_content_feed', 'featuredtoRSS');
It should look something like below. Note that, I have changed the image size to Full.
You can refresh your website and check the results. Don’t forget to clear the cache if you are using any.
You can achieve the same thing with first code by modifying “get_the_content” to “get_the_excerpt” and removing last “the_content_feed” line.
function rss_post_thumbnail($content) { global $post; if(has_post_thumbnail($post->ID)) { $content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_excerpt(); } return $content; } add_filter('the_excerpt_rss', 'rss_post_thumbnail');
Testing your WordPress RSS Feed
You can use below online tools to check validity and display of your RSS feeds.
Does these codes work for you? If not, let me know your issues and I will try to resolve those.