在 WordPress RSS Feed 中添加特色图片

2022年08月6日16:55:49 发表评论 热度265 ℃

如果您在 WordPress 网站上使用 RSS 提要,您会注意到特色图片默认不包含在 RSS 提要的帖子中。

其实如果主题支持特色图像(缩略图),在主题的 functions.php 文件下加入以下代码就可以实现RSS 中输出自定义特色图像(缩略图)的功能。

在 WordPress RSS Feed 中添加特色图片

  1. /**
  2.  * Featured image to RSS Feed.
  3.  */
  4. function featuredtoRSS($content) {
  5. global $post;
  6. if ( has_post_thumbnail( $post->ID ) ){
  7. $content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
  8. }
  9. return $content;
  10. }
  11. add_filter('the_excerpt_rss', 'featuredtoRSS');
  12. add_filter('the_content_feed', 'featuredtoRSS');
瓜皮猪

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: