Tulip Media

Entrepreneurial thoughts

WordPress tip: how to display featured images on RSS feed

Here is a simple code which let you display the featured images of your posts in your RSS feed…

…in that way, your featured images will be displayed on all your social feeds, like Facebook for instance.

Please add this code in your functions.php file:

  • Use this code to display the featured images:

function imageRSS($content) {
global $post;
if (has_post_thumbnail($post->ID)){
$content = » . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float: right; margin:0 0 10px 10px;' ) ) . » . $content;
}
return $content;
}

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

  • Use this code if you have the Get the picture plugin, in order to scan the pictures in your post if it doesn't have featured image:

function imageRSS($content) {
global $post;
if (has_post_thumbnail($post->ID)){
$content = » . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float: right; margin:0 0 10px 10px;' ) ) . » . $content;
}
else {
$content = » . get_the_image(array('width' => 150, 'image_scan' => true , 'image_class' => », 'meta_key' => array( 'Thumbnail', 'thumbnail' ))) . » . $content;
}
return $content;
}

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

function show_image_feed($content) {

global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
);

$attachment = get_posts($args);

if (1TP4Attachment) {

$content = '

' . $content. '
ID).' »>Read the rest.'; } return $content; } add_filter('the_excerpt_rss', 'show_image_feed');

 

My latest tweets

New shorts on Blooness 👉 Training dedicated to the best oilseeds for health is finally available in audio format https://buff.ly/3xo9fTS
https://buff.ly/43DkrYR

New shorts on Blooness 👉 If there was only one supplement to take, it would be magnesium (along with vitamin D). The complete guide to the best multivitamins on the market still available here with free access https://buff.ly/49bHqvp
https://buff.ly/49c3rKK

New shorts on Blooness 👉 The latest Blooness training on #proteins is available in audio format https://buff.ly/4aijbMW
https://buff.ly/3TP67cB

Load more

Don't miss business advice by email

No spam, just an email when new content is published.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEN