- This topic has 7 replies, 2 voices, and was last updated 3 years, 11 months ago by
Fernando.
-
AuthorPosts
-
June 6, 2022 at 7:01 pm #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,
RachelJune 6, 2022 at 8:45 pm #2245625Fernando 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!
June 6, 2022 at 9:24 pm #2245650Rachel
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,
RachelJune 7, 2022 at 1:43 am #2245794Fernando 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.
June 8, 2022 at 7:52 pm #2247824Rachel
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.
June 8, 2022 at 11:11 pm #2247896Fernando 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.
June 9, 2022 at 3:35 am #2248063Rachel
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.
June 9, 2022 at 5:00 pm #2248781Fernando Customer Support
I see. Hope the email goes well! You’re welcome Rachel!
-
AuthorPosts
- You must be logged in to reply to this topic.