Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rmorse/cd56a087c6f4c7714c34 to your computer and use it in GitHub Desktop.
Save rmorse/cd56a087c6f4c7714c34 to your computer and use it in GitHub Desktop.
Updated to to use a specific custom image size, with no fall back - better to have no image instead
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;
$attachment_id = get_post_thumbnail_id($post->ID);
$mime = get_post_mime_type($attachment->ID);
$image_info = wp_get_attachment_image_src($attachment_id, 'custom-image-size');
if ($image_info) {
echo '<enclosure url="'.$image_info[0].'" length="" type="'.$mime.'"/>';
}
return $item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment