admin管理员组文章数量:1122846
I want to add the featured image to my RSS feed.
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail', 20, 1);
add_filter('the_content_feed', 'rss_post_thumbnail', 20, 1);
With this snippet the thumbnail is shown, but the content is not generated correct. It is shown with shortcodes and its not formatted...
When i use the snippet below, where i remove the ordering of filters, the content is shown, but the featured image is missing:
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');
I want to add the featured image to my RSS feed.
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail', 20, 1);
add_filter('the_content_feed', 'rss_post_thumbnail', 20, 1);
With this snippet the thumbnail is shown, but the content is not generated correct. It is shown with shortcodes and its not formatted...
When i use the snippet below, where i remove the ordering of filters, the content is shown, but the featured image is missing:
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');
Share
Improve this question
asked Feb 20, 2020 at 11:42
LovinQuaQuaLovinQuaQua
733 silver badges18 bronze badges
2
- "With this snippet the thumbnail is shown, but the content is not generated correct." - you're building the output from get_the_content() not $content, and I'd guess the latter has the shortcodes expanded (via the 'the_content' filter). I can't explain the second behaviour though. – Rup Commented Feb 20, 2020 at 11:56
- Note also that the_content_feed takes two arguments, $content and $feed_type, not 1 as you've got in your first add_filter. – Rup Commented Feb 20, 2020 at 12:01
1 Answer
Reset to default 0I just found the right solution:
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$output = '<p>' . get_the_post_thumbnail($post->ID) . '</p>';
}
return $output . $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail', 20, 1);
add_filter('the_content_feed', 'rss_post_thumbnail', 20, 1);
本文标签: Get featured image from post on RSS feed
版权声明:本文标题:Get featured image from post on RSS feed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294373a1929344.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论