Site logo

[Resolved] RSS Feed Image Not Displayed After Adding Function

Home Forums Support [Resolved] RSS Feed Image Not Displayed After Adding Function

Home Forums Support RSS Feed Image Not Displayed After Adding Function

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2245589
    Rachel

    Hi there,

    I have added the following snippet to my site (listed in private info) to enable the featured image for a post to be displayed in the RSS Feed:

    add_filter( ‘the_content’, ‘featured_image_in_feed’ );
    function featured_image_in_feed( $content ) {
    global $post;
    if( is_feed() ) {
    if ( has_post_thumbnail( $post->ID ) ){
    $output = get_the_post_thumbnail( $post->ID, ‘medium’, array( ‘style’ => ‘float:right; margin:0 0 10px 10px;’ ) );
    $content = $output . $content;
    }
    }
    return $content;
    }

    However, when I check the feed, there are no image files listed in the feed for each post.

    Can you please advise if there is an additional step required for the images to be fed through to the RSS feed? Or will it only display for future posts published?

    Thanks,
    Rachel

    #2245625
    Fernando
    Customer Support

    Hi Rachel,

    Can you check if the quotation marks in your code are straight, and not slanted. Sometimes, copying and pasting makes the quotation marks slanted which causes issues.

    If it still doesn’t work, alternatively, can you try either steps provided here and see how it goes: https://www.wpbeginner.com/wp-tutorials/how-to-add-post-thumbnail-to-your-wordpress-rss-feeds/

    Hope this helps!

    #2245650
    Rachel

    Hi,

    I checked the quotation marks aren’t slanted.

    The snippet I added was provided by Tom at Generatepress in the support forum to another user a while back – so is this code no longer correct? I have my site set up to show the excerpt not the full article, so should this piece of code work in that instance?

    Thanks,
    Rachel

    #2245794
    Fernando
    Customer Support

    Hi Rachel,

    That code should work.

    Example: https://share.getcloudapp.com/7Ku6yJxo

    If it doesn’t I tested this code as well and it seems to be working as an alternative:

    function wpcontent_featured_image_in_feed( $content ) {
        global $post;
        if( has_post_thumbnail( $post->ID ) ) {
            $content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . $content;
        }
        return $content;
    }
    add_filter( 'the_excerpt_rss', 'wpcontent_featured_image_in_feed' );
    add_filter( 'the_content_feed', 'wpcontent_featured_image_in_feed' );

    Go to Settings > Reading, then set a different value in “Syndication feeds show the most recent” to refresh the feed.

    Kindly let us know how it goes.

    #2247824
    Rachel

    I have the featured image disabled for posts as I am using a header element with a background image – could this be why the images aren’t displayed for the posts in the RSS feed? Each post has a featured image, I just don’t have it selected in the customiser to display on each post.

    #2247896
    Fernando
    Customer Support

    They should work still. I checked on an RSS reader(Feedly) just now, and I can see the images: https://share.getcloudapp.com/JruoWDJL

    Can you recheck again? Perhaps you can use Feedly as well?: https://feedly.com/

    Kindly let us know.

    #2248063
    Rachel

    That is interesting – if I look at the RSS code for the feed, there is no image URL listed for each item – so not sure how that is being pulled!

    I have an RSS email going out early next week so I will check to see if it was able to pull the images. I am assuming it will if feedly can see them.

    Thanks for your help.

    #2248781
    Fernando
    Customer Support

    I see. Hope the email goes well! You’re welcome Rachel!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.