WordPress: aggiungere le thumbnail ai feed RSS

WordPress: aggiungere le thumbnail ai feed RSS

Possiamo aggiungere la thumbnail (miniatura) dell'immagine in evidenza collegata ad un post di WordPress anche ai nostri feed RSS. Si tratta semplicemente di creare una funzione da associare a due filtri di WordPress. Vediamo come.

Aggiungete il seguente codice al file functions.php del vostro tema:


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

La funzione verifica che il post corrente abbia un'immagine associata ed eventualmente restituisce il contenuto del post inserendo la thumbnail prima di quest'ultimo.

Torna su