How replace individual elements in the RSS feed with a single string

We’re sending RSS emails out to our list and would like to include the categories and tags.

But when we add them, due to the way WordPress delivers them, they just end up in one big long string/stacked end to end, one after the other, like this:

Digital ContentSocial MediaFacebookZuckerberg

I’m trying to find a way to get rid of the individual elements and just call my main, comma separated, category list, inside a single element, instead.

So instead of:

<category><![CDATA[Digital Content]]></category>
<category><![CDATA[Social Media]]></category>
<category><![CDATA[Facebook]]></category>
<category><![CDATA[Zuckerberg]]></category>

We’d have something like:

<category><![CDATA[Digital Content, Social Media, Facebook, Zuckerberg]]></category>

I’m looking at the_category_rss(), which seems designed for the purpose, but no matter what code I try I can’t get it to override the individual s.

function rtt_rss_cats($the_list,$type) {
$the_list = “PUT SOMETHING ELSE HERE”;
return $the_list;
}
add_filter(‘the_category_rss’, ‘rtt_rss_cats’, 10, 1);

The main function appears to be get_the_category_rss(), and includes the filter. I just can’t get it to work/override this:

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( get_bloginfo_rss( ‘url’ ) ), esc_attr( $cat_name ) );
} else {
$the_list .= “tt<category><![CDATA[” . @html_entity_decode( $cat_name, ENT_COMPAT, get_option( ‘blog_charset’ ) ) . “]]></category>n”;
}
}
/**
* Filters all of the post categories for display in a feed.
*
* @since 1.2.0
*
* @param string $the_list All of the RSS post categories.
* @param string $type Type of feed. Possible values include ‘rss2’, ‘atom’.
* Default ‘rss2’.
*/
return apply_filters( ‘the_category_rss’, $the_list, $type );
}

Read more here:: <a href=https://wordpress.stackexchange.com/questions/344514/how-replace-individual-category-elements-in-the-rss-feed-with-a-single-catego target="_blank" title="How replace individual elements in the RSS feed with a single string” rel=nofollow>How replace individual elements in the RSS feed with a single string

Leave a Reply

Your email address will not be published. Required fields are marked *