我试图在一个运行pinbin儿童主题的博客上向我的RSS提要添加特色图像。
当我安装并激活插件“将特色图像添加到RSS提要”时,它就可以工作了。
当我尝试在子函数中粘贴此插件的代码时。php文件它不起作用(事实上,当它粘贴到我的functions.php文件中时,我在internet上发现的任何代码都不起作用,例如Can't Display Featured Image in RSS Feed )
代码为
function add_featured_image_to_feed($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = \'\' . get_the_post_thumbnail( $post->ID, \'large\' ) . \'\' . $content;
}
return $content;
}
add_filter(\'the_excerpt_rss\', \'add_featured_image_to_feed\', 1000, 1);
add_filter(\'the_content_feed\', \'add_featured_image_to_feed\', 1000, 1);
我会做错什么?当然,我的博客使用了child主题,我已经检查了child函数中的其他函数。php文件正在运行。
SO网友:Brad Dalton
You may need to clear your Feeds cache to see the image after adding this code.
function wpsitesdotnet_post_thumbnail_rss($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = \'\' . get_the_post_thumbnail( $post->ID, \'rss-image\', array( \'class\' =>
\'aligncenter\' ) );
}
return $content;
}
add_filter(\'the_content_feed\', \'wpsitesdotnet_post_thumbnail_rss\');
add_filter(\'the_excerpt_rss\', \'wpsitesdotnet_post_thumbnail_rss\');
Source http://wpsites.net/web-design/add-featured-image-thumbnail-from-post-to-rss-feed/