Last active
August 10, 2017 08:23
-
-
Save vpadhariya/94442ba216a19c0345291456a8311513 to your computer and use it in GitHub Desktop.
WordPress Add Taxonomy (Category or Tag) before post title in RSS Feeds
This file contains hidden or 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 | |
/** | |
* 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