如何在 WordPress RSS Feed 中顯示精選圖片
Last Updated on October 7, 2022
儘管有些人可能認為 RSS 提要已失效,但許多其他服務仍在使用它們。
像我的部落格,至目前還是使用 Feedly 來閱讀 RSS 文章。
Code Snippets
步驟一
安裝免費的 Code Snippets 外掛,好處是不必修改佈景主題的 functions.php 文件或弄亂子主題。
步驟二
從「Code Snippets → Add New 」創建一個新的代碼段,可以隨意命名,例如:featured-images-rss-feed。
步驟三
將以下代碼放入代碼段中。
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
Photo by Johan Mouchet on Unsplash