Support » Fixing WordPress » Customizing feeds and feed urls

  • Resolved hasund


    I am using WordPress more like a CMS than a blog as such, and I want to prevent certain categories from being displayed in the main feed. I can get around this by playing with the feed url and using for example “?feed=rss2&cat=-4&cat=-5” (which excludes categories 4 and 5). However, this looks “hackish” and ugly, I want the main feed to have the default WP rss url of “”.

    mod_rewrite is alive and working, but I have a hard time figuring out regular expressions and how to do this.

    Are there any .htaccess gurus out there that might know the magic code? I’ve tried the following, without success:

    RewriteBase /
    RewriteRule ^feed/?$ /?feed=rss2&cat=-4&cat=-5[R,L]

Viewing 8 replies - 1 through 8 (of 8 total)
  • The simple way is to use the Category Visibility plugin:

    It lets you hide categories from the feed, or the homepage, or the archives, etc, etc. Very configurable.

    Ah, I had that installed already actually, but I’d forgotten about its capabilities. Thanks, it will do for now.

    However, the plugin has its limitations (hiding a category from feeds hides it from its own feed too, not just from the main feed), so I’m hoping to be able to use a mod_rewrite solution.

    So you only want to rewrite the main feed and not all the category feeds as well?

    RewriteRule ^/feed$ /index.php?feed=rss2&cat=-4&cat=-5 [R,L]

    Should work, I think.

    For some reason it doesn’t. I’ll try some more in the morning.

    I think the least complicated thing to do is hack away at the wp-rss.php, wp-rss2.php, and other such files in the root. That’s what I did, anyway. I have written code to select which categories go into the main feed without upsetting category feeds, and also insert meta data (if available) for posts in certain categories. Have at it!

    I am sure there are more graceful solutions, but my resources(meaning technical knowledge and time) are limited. I got it to work in the .htaccess. Excluding more than one category doesn’t seem to work, so I had to add the categories to be included instead, like this:

    RewriteRule ^feed$ ?feed=rss2&cat=1+2+3+6+7 [L]
    RewriteRule ^feed/$ ?feed=rss2&cat=1+2+3+6+7 [L]

    But of course, for every problem solved another one comes along. I noticed that my category feeds ( got the title from the site, just like the main feed ( does. This makes them look indistinguishable in a feed reader, confusing users. Obviously I want the main feed to be titled “site name” and the category feeds to be titled “site name: category”. It would also be nice to have category-specific links and descriptions. So I used some code found elsewhere on this forum:

    if (is_category()) {
    foreach((get_the_category()) as $cat) {
    $titulo = get_bloginfo_rss('name') ." :". $cat->cat_name;
    $descripcion = $cat->category_description;
    $enlace = get_bloginfo_rss('url') . "/" . $cat->category_nicename . "/";
    else {
    $titulo = get_bloginfo_rss('name');
    $descripcion = get_bloginfo_rss("description");
    $enlace = get_bloginfo_rss('url');
    <title><?php echo $titulo; ?></title>
    <link><?php echo $enlace; ?></link>
    <description><?php echo $descripcion; ?></description>

    It works fine for the category feeds.

    But here’s the newborn problem: Because the main feed actually is a composition of category feeds, the system interprets it as one – thus grabbing the title from the category that happens to be assigned to the first post.

    Any ideas?

    Well, I usually consider mucking around with .htaccess to be anything but graceful when it comes to WP 🙂

    As for your current problem, a judicious use of is_home() and is_cat() should help out…

    Yup, got it to work somehow…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Customizing feeds and feed urls’ is closed to new replies.