Skip to content

Instantly share code, notes, and snippets.

@tomharrigan
Created May 29, 2015 19:03
Show Gist options
  • Save tomharrigan/8a8c82064ef8ca948c67 to your computer and use it in GitHub Desktop.
Save tomharrigan/8a8c82064ef8ca948c67 to your computer and use it in GitHub Desktop.
Add image to RSS feed
add_action('rss_item', 'wp_rss_img_include');
add_action('rss2_item', 'wp_rss_img_include');
function wp_rss_img_include (){
global $post;
if( has_post_thumbnail( $post->ID ) ) {
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$img = wp_get_attachment_image_src( $thumbnail_id, 'full' );
if ( !empty( $img ) ) {
$url = parse_url( $img[0] );
$path = ABSPATH . ltrim( $url['path'], '/' );
if ( file_exists( $path ) ) {
echo '<media:content url="' . $img[0] . '" width="' . $img[1] . '" height="' . $img[2] . '" medium="image" type="'. get_post_mime_type( $thumbnail_id ) . '" />';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment