1
私はこの機能をfunction.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>
と私はget_post_thumnail()
だけのタグを含む文字列を返しているので、あなただけのことができるようにする必要があり、それは
<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