用PHP自定义WordPress RSS内容

自己history网站的宣传是用的默认RSS,但内容有点无语了,而且长度莫名奇怪的固定为特定长度值,就尝试自己去弄。

步骤

  • 在主题的functions.php中添加代码如下所示:
function feed_copyright() {
    $post = get_the_content();
    $all = strip_tags($post);
    $content =  mb_strimwidth($all, 0, 200, '...');
    return $content;
}
add_filter ('the_excerpt_rss', 'feed_copyright');
add_filter('the_content_feed', 'feed_copyright');
  • 能修改的内容就是下图中红圈所示内容,也就是我们阅读时显示的内容,具体怎么搞按需求去弄就行了,我这里就是把字数加长到100字。

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *