Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Post Kinds for Wordpress kinds as a prefix to titles in RSS. https://danq.me/2020/03/01/post-kinds-rss/
<?php
// Make titles in RSS feed be prefixed by the Kind of the post.
function add_kind_to_rss_post_title(){
$kinds = wp_get_post_terms( get_the_ID(), 'kind' );
if( ! isset( $kinds ) || empty( $kinds ) ) return get_the_title(); // sanity-check.
$kind = $kinds[0]->name;
$title = get_the_title();
return trim( "[{$kind}] {$title}" );
}
add_filter( 'the_title_rss', 'add_kind_to_rss_post_title', 4 ); // priority 4 to ensure it happens BEFORE default escaping filters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment