categories - Replace category titles inside RSS feed

admin2025-06-03  4

I need to replace titles in <category> ... </ category> tag inside the default RSS feed (mywebsite/feed/).

Of course, it would be more convenient to just rename the categories, but for a number of reasons I can't do that.

This is the example of what I need:

  • Categories "Apples" and "Pears" inside the RSS feed should be replaced with "Fruits".
  • Categories "Raspberry" and "Strawberry" inside the RSS feed should be replaced with "Berries".

I am very bad at functions and filters yet. I would be very grateful to those who help.

EDIT: that's what I managed to do to make it work with get_post_type()

function changeRSStitles($content) {
if (get_post_type($post) == 'post') {
    $content = '<category>Fruits</category>';
}else {
    $content = $content;
}
return $content;
}
add_filter('the_category_rss', 'changeRSStitles');

But I couldn't get it to work with get_the_category()

function changeRSStitles($content) {
if (get_the_category($id) == '1') {
    $content = '<category>Fruits</category>';
}else {
    $content = $content;
}
return $content;
}
add_filter('the_category_rss', 'changeRSStitles');

Just nothing happens. Any ideas?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748941112a315010.html

最新回复(0)