Site logo

Archived topic

Featured image in RSS

9 replies · Started by septiady on September 11, 2020

Viewing posts 1–10 of 10

How do i add featured image in RSS? Google News doesnt show the correct image. I searched that you have to add image code in rss.

thx for the help

i am a noob about this. where do i post this code? thank for the help. can you guide me step by step like.

element>?>?>?

WP Beginenr
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');

OR TOM'S

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;' ) );
$output .= '

' . get_the_post_thumbnail_caption( $post->ID ) . '

';
$content = $output . $content;
}
}
return $content;
}

Alright, i do not know any coding, i found this in wpbeginner. So which code do i use? i am using generatepress read theme.

Sorry for any stupid question. Thank you

Either of WP Beginner or Toms should work. The only difference is that Toms will also output the Image Caption if one exists.

Make sure you copy the code from the original topic or the WP Beginners sites :)

Leave it as the default 'Run snippet everywhere'

priority is 10?

thank you man, generatepress has awesome support^^

Yes, priority can be left at 10

This archived topic is closed to new replies.