如何从Wordpress RSS源中排除媒体文件?

如何从Wordpress RSS源中排除媒体文件?,wordpress,rss,Wordpress,Rss,我有新闻聚合器的自定义RSS模板。是否可以从_content_feed()中排除所有媒体文件,如图像/视频? 我需要显示纯文本 这是我的模板 header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true ); $frequency = 1; $duration = 'hourly'; $postimages = wp

我有新闻聚合器的自定义RSS模板。是否可以从_content_feed()中排除所有媒体文件,如图像/视频? 我需要显示纯文本

这是我的模板

header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
$frequency  = 1;       
$duration   = 'hourly'; 
$postimages = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' );
if ( $postimages ) {
    $postimage = $postimages[0];
} else {
    $postimage = get_stylesheet_directory_uri() . '/images/default.jpg';
}


echo '<?xml version="1.0" encoding="UTF-8"?>' ."\r\n"; ?>
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        <title><?php bloginfo_rss( 'name' ); wp_title_rss(); ?></title>
        <link><?php bloginfo_rss( 'url' ) ?></link>
        <description><?php bloginfo_rss( 'description' ) ?></description>
        <yandex:logo></yandex:logo>
        <yandex:logo type="square"></yandex:logo>
        <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s +0200', get_lastpostmodified( 'GMT' ), false ); ?></lastBuildDate>
        <language><?php bloginfo_rss( 'language' ); ?></language>


        <?php do_action( 'rss2_head' ); ?>
        <?php while( have_posts()) : the_post(); ?>

            <item>
                <title><?php the_title_rss(); ?></title>
                <link><?php the_permalink_rss(); ?></link>
                <guid isPermaLink="false"><?php the_guid(); ?></guid>
                <author><?php the_author(); ?></author>
                <enclosure url="<?php echo esc_url( $postimage ); ?>" type="image/jpeg" />
                <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0200', get_date_from_gmt(get_post_time('Y-m-d H:i:s', true)), false ); ?></pubDate>
                <description>
                    <![CDATA[<?php the_excerpt_rss(); ?>]]>
                </description>
                <yandex:full-text>
                    <![CDATA[<?php the_content_feed();  ?>]]>
                </yandex:full-text>
            </item>

        <?php endwhile; ?>
    </channel>
</rss>
header('Content Type:'.feed_Content_Type('rss http'));charset='.get_选项('blog_charset'),true);
$frequency=1;
$duration='每小时';
$postmages=wp_get_attachment_image_src(get_post_缩略图_id(get_id()),'large');
如果($postmages){
$postimage=$postimages[0];
}否则{
$postimage=get_stylesheet_directory_uri()。/images/default.jpg';
}
回显“”。“\r\n”?>
这是解决办法


要显示RSS提要中文章的纯文本,只需更改内容提要()
to
echo wp_strip_all_标签(获取内容())在您的提要模板中。

虽然这段代码可以回答这个问题,但最好包含一些上下文,解释它是如何工作的以及何时使用它。从长远来看,只使用代码的答案是没有用的。
add_filter( "the_content_feed", "excludeimg" ) ;
function excludeimg($content) {
     $content = preg_replace('#(<img.*?>).*?(/>)#', '$1$2', $content);
     return $content; 
   }
?>