admin管理员组文章数量:1122826
One news aggregator wants to have RSS feed without any links into the <description>
field. So I try to use this code in functions.php
to remove <a href></a>
tags, but it doesn’t work. What’s wrong? How can I remove the tags but keep intact all the text?
add_filter('the_content', 'my_custom_feed');
function my_custom_feed( $content ){
global $post;
if ( ! is_feed() )
return $content;
// Remove all shortcodes
$content = strip_shortcodes( $post->post_content );
$content = strip_tags( $content );
// Remove all html tags, except these
$my_allowed_tags = array(
'p' => array(),
'strong' => array(),
'em' => array(),
'img' => array( 'src' => array(), 'width' => array(), 'height' => array() ),
);
$content = wp_kses( $content, $my_allowed_tags );
// Balance tags
$content = balanceTags( $content, true );
return $content;
}
One news aggregator wants to have RSS feed without any links into the <description>
field. So I try to use this code in functions.php
to remove <a href></a>
tags, but it doesn’t work. What’s wrong? How can I remove the tags but keep intact all the text?
add_filter('the_content', 'my_custom_feed');
function my_custom_feed( $content ){
global $post;
if ( ! is_feed() )
return $content;
// Remove all shortcodes
$content = strip_shortcodes( $post->post_content );
$content = strip_tags( $content );
// Remove all html tags, except these
$my_allowed_tags = array(
'p' => array(),
'strong' => array(),
'em' => array(),
'img' => array( 'src' => array(), 'width' => array(), 'height' => array() ),
);
$content = wp_kses( $content, $my_allowed_tags );
// Balance tags
$content = balanceTags( $content, true );
return $content;
}
Share
Improve this question
asked Jun 26, 2017 at 13:22
YuriYuri
311 silver badge2 bronze badges
1
- Above code is working well. The problem was with caching plugin. Shame on me. – Yuri Commented Jun 27, 2017 at 0:00
1 Answer
Reset to default 0You haven't specified how it doesn't work :)
Does it remove some links or doesn't do anything at all. Anyway, to alter the content of every RSS item you can use rss_item() hook, or rss2_item() depending which stream is your target.
add_filter('rss_item', 'custom_item_content');
function custom_item_content($content) {
// alter your $content here
return $content;
}
本文标签: How can I remove certain HTML tags from the RSS feed
版权声明:本文标题:How can I remove certain HTML tags from the RSS feed? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294541a1929380.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论