Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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/… –  bungeshea 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 –  bungeshea May 14 '13 at 7:56
    
Worked great. Thank you. –  Paul Williams May 18 '13 at 23:15
add comment

Your Answer

 
discard

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.