Category Name Before Feed Item Titles
Puts the post's category in front of each title in your feeds, for example "[Recipes] Easy Pancakes", so subscribers can scan topics at a glance.
Opens WPIDE on
Code
// Format of the prefix; %s is the category name.
$wpide_feed_title_prefix = '[%s] ';
add_filter( 'the_title_rss', function ( $title ) use ( $wpide_feed_title_prefix ) {
if ( 'post' !== get_post_type() ) {
return $title;
}
$default = (int) get_option( 'default_category' );
foreach ( get_the_category() as $category ) {
if ( (int) $category->term_id !== $default ) {
return sprintf( $wpide_feed_title_prefix, wp_strip_all_tags( $category->name ) ) . $title;
}
}
return $title;
}, 9 ); // Before WordPress escapes feed titles (priority 10).
Notes
The default "Uncategorized" category is skipped; change the format string to use another style, such as "Recipes: ".
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.