Editing Category RSS Feeds

I have the following PHP code below that I would like to add to the category feed in WordPress.

<?php if(get_the_post_thumbnail()): ?>
<featured-item><?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?></featured-item>
<?php endif; ?>

I know that I can edit feed-rss2.php to add it into the general feed. But the same code isn’t allowing me to add it to the category view of the same RSS feed.

Read More

Where do I place this code for the generated RSS feed?

Related posts

1 comment

  1. FYI, you should never hack the WordPress core files. Instead, WordPress provides the handy rss2_item action hook. All we need to do is check if we’re on a category feed or not:

    function wpse_99336_category_feed_item() {
    
        if ( is_category() && get_the_post_thumbnail() ) {
            printf ( '<featured-item>%s</featured-item>',
                wp_get_attachment_url( get_post_thumbnail_id() )
            );
        }
    }
    add_action( 'rss2_item', 'wpse_99336_category_feed_item' );
    

Comments are closed.