How can I remove certain HTML tags from the RSS feed?

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;
}

Topic feed tags rss Wordpress

Category Web


You 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;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.