WordPressのRSSフィードに、投稿以外にも、全ての固定ページ及びCustom Post Typeの投稿を配信するようにするには以下のタグをfunctions.phpに追加するとRSSフィードにCustom Post Typeを含む全ての投稿を含めることができます。 RSSフィードに全ての固...
WordPressのRSSフィードに、投稿以外にも、全ての固定ページ及びCustom Post Typeの投稿を配信するようにするには以下のタグをfunctions.phpに追加するとRSSフィードにCustom Post Typeを含む全ての投稿を含めることができます。
RSSフィードに全ての固定ページ及びCustom Post Typeを含む投稿を配信する
function custom_post_rss_set($query) { if ( is_feed() ) { $post_type = $query->get('post_type'); if ( empty($post_type) ){ $query->set( 'post_type','any'); } return $query; } } add_filter( 'pre_get_posts', 'custom_post_rss_set' );
さらに続けてRSSにサムネイル画像を含める
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');
