I have a custom RSS feed that uses <?php the_category_rss('rss2') ?>. I'd like to only show the first category name per post. I've tried using a filter. This isn't right, but I'm not sure how to work it.

add_filter('the_category_rss', 'remove_rss_categories');

function remove_rss_categories( $the_list ) {

    $categories = get_the_category();
    $category = $categories[0]->name;

    $the_list = esc_html("<category><![CDATA[{$category}]]></category>");

    return $the_list;

Your Answer

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

Browse other questions tagged or ask your own question.