How can I exclude tags from category_rss function?

I have been struggling with the following problem:

The default wordpress RSS Feed includes also tags in category function. As a result, if you use a merge tag to show the post category (i.e. I am using RSS campaign on Mailchimp to send emails to my subscribers) it shows the category and in addition all the tags.

Read More

I looked around and located the file ‘/wp-includes/feed.php’ on line #301 there’s the relevant code. I am including it here as well:

function get_the_category_rss($type = null) {
    if ( empty($type) )
        $type = get_default_feed();
    $categories = get_the_category();
    $tags = get_the_tags();
    $the_list = '';
    $cat_names = array();

    $filter = 'rss';
    if ( 'atom' == $type )
        $filter = 'raw';

    if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
        $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
    }

    if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
        $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
    }

    $cat_names = array_unique($cat_names);

    foreach ( $cat_names as $cat_name ) {
        if ( 'rdf' == $type )
            $the_list .= "tt<dc:subject><![CDATA[$cat_name]]></dc:subject>n";
        elseif ( 'atom' == $type )
            $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), esc_attr( $cat_name ) );
        else
            $the_list .= "tt<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>n";
    }

    return apply_filters('the_category_rss', $the_list, $type);
}

I understand that I can fix the problem by deleting the following lines:

$tags = get_the_tags();

and

    if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
            $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
}

I don’t want to edit core files though. I also tried to find a plugin, but no luck.

Is there a filter I could use to resolve this in order to avoid editing core files?

Thank you in advance for any help!
Kat

Related posts

1 comment

  1. Try this – think I found this from little mike.

    add_filter('get_the_tags', 'strip_tags_from_feeds');
    function strip_tags_from_feeds($terms) {
        if (is_feed())
            return array();
        return $terms;
    }
    

Comments are closed.