title: Print only parent categories of post in custom RSS feed
body: <p>I'm trying to print only the parent category for each post and a permalink to that category within a custom Wordpress RSS feed. </p>
  
  <p>Using <code>&lt;?php the_category_rss(); ?&gt;</code> prints all categories for a post (parent and child categories) like this: </p>
  
  <pre><code>&lt;category&gt;&lt;![CDATA[Category 1]]&gt;&lt;/category&gt;
  &lt;category&gt;&lt;![CDATA[Category 2]]&gt;&lt;/category&gt;
  &lt;category&gt;&lt;![CDATA[Category 3]]&gt;&lt;/category&gt;
  </code></pre>
  
  <p>I'd like to print only the parent categories for a post rather than parent and child categories. </p>
  
  <p>I'm also looking for the proper way to print the parent category's permalink within the RSS feed. </p>
  
  <p>I have a feeling the way to do this is a filter, but I'm not sure how to implement it. This is what I have right now, but it returns a <code>1</code> instead of the parent category name: </p>
  
  <pre><code>add_filter('the_category_rss', 'only_parent_rss_categories');
  
  function only_parent_rss_categories( $allparents ) {
  
      $categories = get_the_category();
      $category = $category-&gt;category_parent == 0;
  
      $allparents= esc_html("&lt;category&gt;&lt;![CDATA[{$category}]]&gt;&lt;/category&gt;");
  
      return $allparents;
  }
  </code></pre>