Last active
December 10, 2020 15:30
-
-
Save herbie4/bb9c5b052fc4998285c6db33c42485d1 to your computer and use it in GitHub Desktop.
WordPress: Add Featured Image to RSS feed, works with Active campaign feeds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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