0

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.

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 .= "\t\t<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 .= "\t\t<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

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;
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.