Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbie4/bb9c5b052fc4998285c6db33c42485d1 to your computer and use it in GitHub Desktop.
Save herbie4/bb9c5b052fc4998285c6db33c42485d1 to your computer and use it in GitHub Desktop.
WordPress: Add Featured Image to RSS feed, works with Active campaign feeds
<?php
/**
* WordPress
* Add Featured Image to RSS feed
* works with Active campaign feeds
**/
// haha.nl - herbert hoekstra - 20201210
function hahadev_rss_add_thumbnail() {
global $post;
$output = '';
if ( has_post_thumbnail( $post->ID ) ) {
$thumbnail_ID = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_ID, 'thumbnail' );
$output .= '<enclosure medium="image" type="image/jpeg"';
$output .= ' url="'. urlencode($thumbnail[0]) .'"';
$output .= ' width="'. $thumbnail[1] .'"';
$output .= ' height="'. $thumbnail[2] .'"';
$output .= ' />';
}
echo $output;
}
add_action( 'rss2_item', 'hahadev_rss_add_thumbnail' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment