Forked from supermethod/Wordpress RSS 2.0 image enclosure
Last active
August 29, 2015 14:20
-
-
Save lustremedia/70aca2cbf4d71959a3f1 to your computer and use it in GitHub Desktop.
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
function feedFilter($query) { | |
if ($query->is_feed) { | |
add_filter('rss2_item', 'feedContentFilter'); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','feedFilter'); | |
function feedContentFilter($item) { | |
global $post; | |
$args = array( | |
'order' => 'ASC', | |
'post_type' => 'attachment', | |
'post_parent' => $post->ID, | |
'post_mime_type' => 'image', | |
'post_status' => null, | |
'numberposts' => 1, | |
); | |
$attachments = get_posts($args); | |
if ($attachments) { | |
foreach ($attachments as $attachment) { | |
$image = wp_get_attachment_image_src($attachment->ID, 'large'); | |
$mime = get_post_mime_type($attachment->ID); | |
} | |
} | |
if ($image) { | |
echo '<enclosure url="'.$image[0].'" length="" type="'.$mime.'"/>'; | |
} | |
return $item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment