Как показать контент без HTML-тегов в ленте WordPress?

Я хочу удалить все теги html из моего собственного фида wordpress. Является ли это возможным? Как это сделать? Я пытался использовать str.replace(/<\/?[^>]+>/gi, '') но это мне совсем не помогает. Вот код, который я использовал для создания собственного фида. Я использую Yoast SEO плагин.

<?php
/*
Template Name: Custom Feed
*/

$numposts = 10;

function yoast_rss_date( $timestamp = null ) {
$timestamp = ($timestamp==null) ? time() : $timestamp;
echo date(DATE_RSS, $timestamp);
}

function yoast_rss_text_limit($string, $length, $replacer = '...') {
$string = strip_tags($string);
if(strlen($string) > $length)
return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
return $string;
}

function rss_noiframe($content) {
$content = preg_replace( '/<iframe(.*)\/iframe>/is', '', $content );
$content = preg_replace( '/<script(.*)\/script>/is', '', $content );
return $content;
}

add_filter('the_excerpt_rss', 'rss_noiframe');
add_filter('the_content_feed', 'rss_noiframe');


$posts = query_posts('showposts='.$numposts.'&cat=7');

$lastpost = $numposts - 1;

header("Content-Type: application/rss+xml; charset=UTF-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>


<rss version="2.0"xmlns:content="http://purl.org/rss/1.0/modules/content/"xmlns:dc="http://purl.org/dc/elements/1.1/"xmlns:media="http://search.yahoo.com/mrss/"xmlns:atom="http://www.w3.org/2005/Atom"xmlns:georss="http://www.georss.org/georss">

<channel>
<title>My Website Feed</title>
<link>http://www.mywebsite.com/</link>
<description>The latest blog posts from mywebsite.com.</description>
<language>en-us</language>
<pubDate><?php yoast_rss_date( strtotime($ps[$lastpost]->post_date_gmt) ); ?></pubDate>
<lastBuildDate><?php yoast_rss_date( strtotime($ps[$lastpost]->post_date_gmt) ); ?></lastBuildDate>
<managingEditor>admin@mywebsite.com (Admin Admin)</managingEditor>
<atom:link href='http://pubsubhubbub.superfeedr.com/' rel='hub' />
<atom:link href="http://www.mywebsite.com/feed/" rel="self" type="application/rss+xml" />

<?php foreach ($posts as $post) { ?>
<?php
global $post;
$author_id=$post->post_author;
?>

<item>
<title><?php echo get_the_title($post->ID); ?></title>
<dc:creator><?php the_author_meta( 'user_nicename', $author_id ); ?></dc:creator>
<link><?php echo get_permalink($post->ID); ?></link>
<description><?php echo '<![CDATA['.rss_noiframe($post->post_content).'<br/><br/>Keep on reading: <a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'.']]>';  ?></description>
<pubDate><?php yoast_rss_date( strtotime($post->post_date_gmt) ); ?></pubDate>
<guid><?php echo get_permalink($post->ID); ?></guid>
<?php
$categories = get_the_category();
foreach ( $categories as $category ) {
?>
<category><?php echo '<![CDATA['.$category->name.']';  ?></category> <?php } ?>


</item>
<?php } ?>

</channel>
</rss>

0

Решение

Как упоминает Qirel Я заменил

<description><?php echo '<![CDATA['.rss_noiframe($post->post_content).'<br/><br/>Keep on reading: <a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'.']]>';  ?></description>

К

        <description><?php echo '<![CDATA['.strip_tags(rss_noiframe($post->post_content)).'<br/><br/>Keep on reading: <a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'.']]>';  ?></description>

Благодарю вас

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector