Last active
March 1, 2020 11:23
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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