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 lustremedia/70aca2cbf4d71959a3f1 to your computer and use it in GitHub Desktop.
Save lustremedia/70aca2cbf4d71959a3f1 to your computer and use it in GitHub Desktop.
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