Skip to content

Instantly share code, notes, and snippets.

@vpadhariya
Last active August 10, 2017 08:23
Show Gist options
  • Save vpadhariya/94442ba216a19c0345291456a8311513 to your computer and use it in GitHub Desktop.
Save vpadhariya/94442ba216a19c0345291456a8311513 to your computer and use it in GitHub Desktop.
WordPress Add Taxonomy (Category or Tag) before post title in RSS Feeds
<?php
/**
* Prepend taxonomy name before feed title for Articles
* This will work for any custom post type or custom taxonomy
*/
function add_feed_item_title($content)
{
global $wp_query;
// Remember we only want to do this for post type 'post'
if ($wp_query->post->post_type != 'post') return;
$postid = $wp_query->post->ID;
$post_title = $wp_query->post->post_title;
$category = wp_get_post_terms($postid, 'category');
$content = $category[0]->name ." : ". htmlspecialchars($post_title);
return $content;
}
add_filter('the_title_rss', 'add_feed_item_title');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment