从PHP字符串-Wordpress RSS源模板中删除HTML

从PHP字符串-Wordpress RSS源模板中删除HTML,php,wordpress,rss,Php,Wordpress,Rss,谢谢你的帮助;到目前为止还没有任何效果,因此添加了更多细节 我正在functions.php中使用下面的函数,以允许我使用自己的RSS模板,该模板工作正常 add_action('init', 'customRSS'); function customRSS(){ add_feed('shows', 'customRSSFunc'); } function customRSSFunc(){ get_template_part('rss', 'shows'); }

谢谢你的帮助;到目前为止还没有任何效果,因此添加了更多细节

我正在functions.php中使用下面的函数,以允许我使用自己的RSS模板,该模板工作正常

add_action('init', 'customRSS');
function customRSS(){
        add_feed('shows', 'customRSSFunc');
}
function customRSSFunc(){
        get_template_part('rss', 'shows');
}
提要的php模板是:

<?php
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
do_action( 'rss_tag_pre', 'rss2' );
?>
<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    <?php do_action( 'rss2_ns' );?>>

<channel>
    <title><?php wp_title_rss(); ?></title>
    <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    <link><?php bloginfo_rss('url') ?></link>
    <description><?php bloginfo_rss("description") ?></description>
    <lastBuildDate><?php
        $date = get_lastpostmodified( 'GMT' );
        echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
    ?></lastBuildDate>
    <language><?php bloginfo_rss( 'language' ); ?></language>
    <sy:updatePeriod><?php
        $duration = 'hourly';
        echo apply_filters( 'rss_update_period', $duration );
    ?></sy:updatePeriod>
    <sy:updateFrequency><?php
        $frequency = '1';
        echo apply_filters( 'rss_update_frequency', $frequency );
    ?></sy:updateFrequency>
    <?php do_action( 'rss2_head'); while( have_posts()) : the_post();?>
    <item>
        <title><?php the_title_rss(); ?></title>
        <date><?php echo customevent_get_start_date( null, false, 'd-m-Y' ); ?></date>
        <time><?php echo customevent_get_start_date( null, false, 'H:i' ); ?></time>
        <price><?php echo customevent_get_cost(); ?></price>
        <link><?php the_permalink_rss(); ?></link>
        <imageurl><?php the_post_thumbnail_url(); ?></imageurl>
        <description>
            <?php
            $content = the_content();
            echo $content ; ?>
        </description>
        <?php rss_enclosure(); ?>
        <?php do_action('rss2_item'); ?>
    </item>
<?php endwhile; ?>
</channel>
</rss>
我有问题的部分是对内容的描述。feed上的输出显示了p标签和更多标签,以及许多位置。两者都需要剥离

我试过:

    <description>
        <?php
        $content = the_content();
        echo wp_filter_nohtml_kses($content); ?>
    </description>

饲料中的产量:

<description>
<p><strong>It took Michael Portillo little more than 10 years to get a seat in the Commons and then rise in power and esteem to a point where he was a favoured leader of his party and possible future PM. A track record like that suggests a privileged friend of the rich and famous ,but since leaving the house almost a decade ago Michael has endeared himself to many with his obvious respect for solid workmanship as found in our great Victorian Railways and the daily life of ordinary hard working citizens. Listen to his story, told with a “ parliamentary standup ” wit, and then feel free to question him about it.      </strong></p>
<p><strong>Full Price &#8211; £19.50 </strong></p>
<p><strong>Concession &#8211; £18.50                                                                                                                                                   </strong></p>
        </description>

您可以将str_替换为strip_标记,如下所示:

<?php
function the_content(){
    echo '<p>&nbspContent</p>';
}

$content = the_content();
echo str_replace(' ','',strip_tags($content));
?>
我测试了这个,效果很好。如果这对你不起作用,你能展示一下你函数的内容吗

编辑:

我还建议您在此处查看html_实体_解码:

这是实现你想要的最好方法。我上面的回答是直接回答你的问题,但这是更好的选择。

使用这个

wp_filter_nohtml_kses( string $data );
检查此链接。

您可以将html\u entity\u decode与strip\u标记结合使用:echo strip\u tagshtml\u entity\u decode$内容;谢谢@Rockhopper。到目前为止运气不好。我已经在上面添加了更多的细节。嗨,迈克-你能不能也展示一下内容的原始内容?啊,对不起,我困了,这是wordpress网站吗?是的!Wordpress网站,使用自定义RSS模板啊,好吧,那可能就是问题所在。老实说,我不接触wordpress,但我有一位同事可能会提供帮助。我明天会和他们聊天,然后回来找你。谢谢瓜拉夫,没什么好运气。我更新了问题的更多细节。您是否使用了wp\u strip\u all\u tags功能??
wp_filter_nohtml_kses( string $data );