WordPress.org

Ready to get started?Download WordPress

Forums

Filter plugin to display category title in RSS feed title (8 posts)

  1. tau_ceti
    Member
    Posted 8 years ago #

    I'm trying to write a plugin to change the title of a category's RSS feed to the title of the category. Right now it's just the name of my blog. I know I can make the change by modifying wp-rss2.php, but I don't want to; I'd like to use a filter. At this point, I'm stumped on how to do it because there's no filter hook for bloginfo_rss. Does anyone know how to do this?

  2. mlanger
    Member
    Posted 7 years ago #

    http://wordpress.org/support/topic/57742?replies=7

    Might help. It was working fine for me until I upgraded to WordPress 2.0.9. Now I can't get it to work.

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    There is a filter hook for bloginfo_rss().
    So, I think this would do it:

    function change_rss_title_for_categories($info) {
    global $wp_query;
    if (is_feed() && is_category() && $info == 'name')
    {
    $cat_obj = $wp_query->get_queried_object();
    return $cat_obj->category_nicename;
    }
    }
    add_filter('bloginfo_rss','change_rss_title_for_categories');

    Edit: Sorry, didn't notice that the original post was 8 months old.

  4. dspilka
    Member
    Posted 7 years ago #

    Has anyone got the filter Otto posted above to work? Or another filter to put the category name as the RSS feed title?

    I've tried the aobve, but it's still got my blog title in the RSS feed title.

  5. dspilka
    Member
    Posted 7 years ago #

    Ok, well I think I figured out a plugin to do this. That is, to make a category RSS feed display the category info (title, url, description) instead of just the blog info. I started with Otto42's example above and came up with this below. I'm sure there are more efficient ways of doing this since I'm just learning wordpress. But I have tested this with wordpress MU 1.2.1.

    <?php
    function change_rss_title_for_categories($show) {
    global $wp_query;
    //get category id for current category
    $cat_obj = $wp_query->get_queried_object();
    $cat_ID = $cat_obj->cat_ID;

    if (is_feed() && is_category())
    {
    //setup blog info
    $blogTitle = get_option('blogname'); //get_bloginfo('name');
    $blogUrl = get_option('siteurl');
    $blogDesc = get_option('blogdescription');

    //set up category info
    $catTitle = trim(wp_title(' ', false));
    $catUrl = get_category_link($cat_ID);
    $catDesc = category_description($cat_ID);

    switch($show) {
    case $blogTitle :
    $output = $blogTitle . " > " . $catTitle;
    break;
    case $blogUrl :
    $output = $catUrl;
    break;
    case $blogDesc:
    $output = $catDesc;
    break;
    default:
    $output = $show;
    break;
    }
    return $output;
    }
    }
    add_filter('bloginfo_rss','change_rss_title_for_categories');
    ?>

  6. JMershon
    Member
    Posted 7 years ago #

    Thank you for posting what worked for you - This is something I have marked...I don't need it yet, but it looks like something that I may need as the site progresses.

  7. dspilka
    Member
    Posted 7 years ago #

    Actually, what I posted above is not quite right...it'll break the regular feeds :) So this below is now working for both for me on WPMU 1.2.1:

    <?php
    /*
    Plugin Name: rssCategoryName
    Plugin URI:
    Description: Customizes RSS feed for category feeds with category title, url, desc
    Version: 1.0
    Author: Dan Spilka
    Author URI:
    */
    function rssCategoryName($show) {
    global $wp_query;

    if (is_feed() && is_category())
    {
    //get category id for current category
    $cat_obj = $wp_query->get_queried_object();
    $cat_ID = $cat_obj->cat_ID;
    //set up category info
    $catTitle = trim(wp_title(' ', false));
    $catUrl = get_category_link($cat_ID);
    $catDesc = category_description($cat_ID);

    //setup blog info
    $blogTitle = get_option('blogname'); //get_bloginfo('name');
    $blogUrl = get_option('siteurl');
    $blogDesc = get_option('blogdescription');

    switch($show) {
    case $blogTitle :
    $output = $blogTitle . " > " . $catTitle;
    break;
    case $blogUrl :
    $output = $catUrl;
    break;
    case $blogDesc:
    $output = $catDesc;
    break;
    default:
    $output = $show;
    break;
    }
    return $output;
    } else {
    return $show;
    }
    }
    add_filter('bloginfo_rss','rssCategoryName');
    ?>

  8. thauknes
    Member
    Posted 7 years ago #

    This might be the solution of my problems at:
    http://www.mightyseek.com/forum/showthread.php?t=747

    Does your fix still work?
    And; if you donĀ“t mind... which files to create and upload..?

    Thanks
    Thor

Topic Closed

This topic has been closed to new replies.

About this Topic