让WordPress RSS Feed输出自定义文章类型的内容

WordPress支持RSS Feed输出,但在整站Feed源只会输出文章(post),如果你添加了自定义文章类型,需要将它们添加到WordPress的整站Feed源中。实现方法很简单,将下面的代码添加到主题的functions.php文件即可:

// 添加自定义文章类型到<a href="https://www.wpdaxue.com/tag/rss" title="查看与【RSS】相关的文章" target="_blank" rel="noopener">RSS</a> Feed输出
function custom_feed_request( $vars ) {
 if (isset($vars['feed']) &amp;&amp; !isset($vars['post_type']))
  $vars['post_type'] = array( 'post', 'product', 'book' );
 return $vars;
}
add_filter( 'request', 'custom_feed_request' );

请根据自己的实际修改第 4 行数组(array)中的文章类型别名。

来源:

https://www.wpdaxue.com/add-custom-post-types-to-rss-feed.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?