郁金香媒体

创业想法

WordPress 提示:将图像放入 RSS 源中

这是一个非常简单的代码,它允许您在 RSS feed 中插入特色图像,这样,当您在 Facebook 等社交网络上转发您的 feed 时,该图像可以伴随您的帖子的标题和演示。

为此,请转到您的文件 函数.php 添加这些代码行:

  • 如果您只想使用允许您展示图像的本机 WordPress 功能,以下是您需要的代码:

函数 imageRSS($content) {
全球$post;
if (has_post_thumbnail($post->ID)){
$内容=”。 get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float: right; margin:0 0 10px 10px;' ) ) . ”。 $含量;
}
返回$内容;
}

add_filter('the_excerpt_rss', 'imageRSS');
add_filter('the_content_feed', 'imageRSS');

  • 如果除了 WordPress 特色图片的原生功能之外,您的某些文章没有特色图片,则 插入 获取图像 将扫描您的文章以查找任何图像以用作特色图像。然后我建议这个代码,如果没有特色图像,将使插件工作 获取图像 查找可能插入到您的文章中的一个:

函数 imageRSS($content) {
全球$post;
if (has_post_thumbnail($post->ID)){
$内容=”。 get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float: right; margin:0 0 10px 10px;' ) ) . ”。 $含量;
}
别的 {
$内容=”。 get_the_image(array('width' => 150, 'image_scan' => true , 'image_class' => ”, 'meta_key' => array( 'Thumbnail', 'thumbnail' ))) 。 ”。 $含量;
}
返回$内容;
}

add_filter('the_excerpt_rss', 'imageRSS');
add_filter('the_content_feed', 'imageRSS');

  • 最后,如果您想检查文章中是否附有图像,以防没有特色图像,您可以使用此代码:

函数 show_image_feed($content) {

全球$post;
$args = 数组(
'post_type' => '附件',
'numberposts' => 1,
'post_status' => 空,
'post_parent' => $post->ID
);

$attachment = get_posts($args);

如果(1TP4附件){

$内容='

'。 $内容。 '
ID)。'”>阅读更多'; } 返回$内容; add_filter('the_excerpt_rss', 'show_image_feed');

 

我最新的推文

Blooness 上的新短片 👉 活力、长寿、减肥:酮地中海饮食中蛋白质的终极指南已在 Blooness 上上线。 https://buff.ly/3xxNvpj
https://buff.ly/4cG2GM4

Blooness 新短片 👉 48 小时后新优质内容出炉,什么内容!这将是关于地中海酮饮食中蛋白质摄入量的最全面的指南。再见 !
https://buff.ly/3L2KbFP

装载更多

不要错过通过电子邮件发送的商业建议

没有垃圾邮件,只有新内容发布时的电子邮件.

4 响应

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

zh_CNZH