$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>filters - How can I exclude tags from category_rss function?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

filters - How can I exclude tags from category_rss function?

matteradmin9PV0评论

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

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

Share Improve this question edited Aug 16, 2013 at 20:14 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Aug 16, 2013 at 15:04 kat_indokat_indo 2331 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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;
}
Post a comment

comment list (0)

  1. No comments so far