Created
May 29, 2015 19:03
-
-
Save tomharrigan/8a8c82064ef8ca948c67 to your computer and use it in GitHub Desktop.
Add image to RSS feed
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
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