PHP Add Post Images to RSS Feed in WordPress

Learn how to add post images to your RSS feed in WordPress using PHP code. Increase engagement and visual appeal for your RSS subscribers.

<?php
function add_post_image_to_rss($content) {
    global $post;
    if (has_post_thumbnail($post->ID)) {
        $content = '<div>' . get_the_post_thumbnail($post->ID, 'large', array('style' => 'margin-bottom: 15px;')) . '</div>' . $content;
    }
    return $content;
}

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