WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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

share|improve this question
up vote 1 down vote accepted

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' );
share|improve this answer
Right I can see that but I'm not sure WHERE to add this in so it gets the hook. If I edit the core files with that edit above, specifically "add_action", I get an error on the feed page. – Paul Williams May 14 '13 at 2:22
@PaulWilliams See: wordpress.stackexchange.com/questions/72160/… – shea May 14 '13 at 3:41
Okay so I do this as a plugin, that's all? – Paul Williams May 14 '13 at 5:22
Yep. Or use another method mentioned in the above link – shea May 14 '13 at 7:56
Worked great. Thank you. – Paul Williams May 18 '13 at 23:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.