1

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?

1 Answer 1

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' );
4
  • 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. May 14, 2013 at 2:22
  • @PaulWilliams See: wordpress.stackexchange.com/questions/72160/…
    – shea
    May 14, 2013 at 3:41
  • Okay so I do this as a plugin, that's all? May 14, 2013 at 5:22
  • Yep. Or use another method mentioned in the above link
    – shea
    May 14, 2013 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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