Forked from supermethod/Wordpress RSS 2.0 image enclosure
Last active
August 29, 2015 14:06
-
-
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
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; | |
$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