Skip to content

Instantly share code, notes, and snippets.

@Dan-Q
Last active March 1, 2020 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan-Q/87027e17456d4102c7c78290023322cd to your computer and use it in GitHub Desktop.
Save Dan-Q/87027e17456d4102c7c78290023322cd to your computer and use it in GitHub Desktop.
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