在codekipple和D\\N的基础上,我想在我的media:content
下面是我所做的:
function add_media_content_to_feed() {
global $post;
$post_id = $post->ID;
if(!has_post_thumbnail($post)) {
return;
}
$thumbnail_size = \'large\';
$thumbnail_id = get_post_thumbnail_id($post_id);
$file = image_get_intermediate_size(get_post_thumbnail_id(), $thumbnail_size);
$url = $file[\'url\'];
$type = $file[\'mime-type\'];
$height = $file[\'height\'];
$width = $file[\'width\'];
$file_size = \'\';
$path = $file[\'path\'];
if($path && 0 !== strpos($path, \'/\') && !preg_match(\'|^.:\\\\\\|\', $path) && (($uploads = wp_get_upload_dir()) && false === $uploads[\'error\'])) {
$path = $uploads[\'basedir\']."/$path";
$file_size = filesize($path);
}
echo sprintf(__(\'<media:content url="%s" type="%s" medium="image" height="%s" width="%s" fileSize="%s" />\'),
$url,
$type,
$height,
$width,
$file_size
);
}
add_action(\'rss2_item\', \'add_media_content_to_feed\');
codekipple的回答实际上还将图像添加到了所有提要内容下面。我希望我的图像高于内容,所以我这样做了:
function add_featured_image_to_feed($content, $feed_type) {
global $post;
$post_id = $post->ID;
if(has_post_thumbnail($post)) {
$content = \'<div class="feed-image">\'.get_the_post_thumbnail($post_id, \'large\').\'</div>\'.$content;
}
return $content;
}
add_filter(\'the_content_feed\', \'add_featured_image_to_feed\', 10, 9999);