1
我有這在我的functions.php工作正常,我只想要特色圖像鏈接到帖子。如何在RSS中包裝精選圖片的帖子url?
add_filter('the_excerpt_rss', 'featured_image_in_feed');
function featured_image_in_feed($content) {
global $post;
if(is_feed()) {
if (has_post_thumbnail($post->ID)){
$output = get_the_post_thumbnail($post->ID, 'medium', array('style' => 'width:100%; margin-bottom:15px; display: inline-block;'));
$content = $output . $content;
}
}
return $content;
}
這是輸出
<description><![CDATA[<img width="564" height="153" src="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg" class="attachment-medium size-medium wp-post-image" alt="checklist" style="width:100%; margin-bottom:15px; display: inline-block;" srcset="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg 564w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-768x208.jpg 768w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484.jpg 880w" sizes="(max-width: 564px) 100vw, 564px" />Teaser text is here]]></description>
而且我想它是
<description><![CDATA[<a href="linktothepost"><img width="564" height="153" src="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg" class="attachment-medium size-medium wp-post-image" alt="checklist" style="width:100%; margin-bottom:15px; display: inline-block;" srcset="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg 564w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-768x208.jpg 768w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484.jpg 880w" sizes="(max-width: 564px) 100vw, 564px" /></a>Teaser text is here]]></description>
相對於?顯示當前與期望的輸出。 – rbellamy