Archived topic
Featured image in RSS
9 replies · Started by septiady on September 11, 2020
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
Hi there,
maybe the code Tom provides here will help:
https://generatepress.com/forums/topic/no-image-captions-in-rss-feed/#post-1192398
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>?>?>?
Sorry should have provided this article on how to add PHP:
https://docs.generatepress.com/article/adding-php/
TLDR: Options:
1. Are you using a Child Theme ? If you are then add the code into your child themes functions.php
2. If you are not using a child theme - then install the Code Snippets plugin:
https://wordpress.org/plugins/code-snippets/
2.1 Dashboard > Snippets > New Snippet
2.2 Paste in the code.
2.3 Click Save and Activate
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 .= '
';
$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 :)
tHANK YOU.
This should my my last reply:
Which should i choose
Thank you^^
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