Tulipe Media

Réflexions entrepreneuriales

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 image 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 ($attachment) {

$content = ‘

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

 

Mes derniers tweets

Nouveau short sur Blooness 👉 Vitalité, longévité, perte de poids : le guide ultime des protéines en diète keto-méditerranéenne est en ligne sur Blooness. https://buff.ly/3xxNvpj
https://buff.ly/4cG2GM4

Nouveau short sur Blooness 👉 Le nouveau contenu premium sort dans 48h, et quel contenu ! Ce sera le guide le plus abouti sur la quantité de protéine à consommer en diète kéto-méditerranéenne. A très bientôt !
https://buff.ly/3L2KbFP

New Post: Combo, la meilleure solution pour en finir avec le casse-tête des plannings et de la gestion RH https://buff.ly/4eE6JtT

Charger plus

Ne manquez pas les conseils business par mail

Pas de spam, juste un mail lorsqu'un nouveau contenu est publié.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFR