I'm using a Google Alerts RSS feed to populate a sidebar widget on my site. It currently shows the link to the article and the published date, but I would also like to display the thumbnail image next to each item. After reading about the issue, I found the problem is that images are not present in the Google Alerts XML. Is there a workaround or code that will fetch the featured image or thumbnail from each source item (article) and display it in my sidebar?
I've tried every plugin related to adding an image to your RSS feed, with negative results. I've tried several code snippets, with negative results.
This is one snippet that failed to work:
`add_action( 'rss2_item', 'add_post_featured_image_as_rss_item_enclosure'
);
function add_post_featured_image_as_rss_item_enclosure() {
if ( ! has_post_thumbnail() )
return;
$thumbnail_size = apply_filters( 'rss_enclosure_image_size',
'thumbnail' );
$thumbnail_id = get_post_thumbnail_id( get_the_ID() );
$thumbnail = image_get_intermediate_size( $thumbnail_id,
$thumbnail_size );
if ( empty( $thumbnail ) )
return;
$upload_dir = wp_upload_dir();
printf(
'<enclosure url="%s" length="%s" type="%s" />',
$thumbnail['url'],
filesize( path_join( $upload_dir['basedir'], $thumbnail['path'] )
),
get_post_mime_type( $thumbnail_id )
);
}
All plugins/code snippets tried didn't produce any error messages, they just did nothing.