title: Getting Wordpress single post primary category
body: <p>I would like to show only the primary category of a single post when it has multiple categories. Using this code at the moment: </p>
  
  <pre><code>&lt;?php
    $perma_cat = get_post_meta($post-&gt;ID , '_category_permalink', true);
    if ( $perma_cat != null ) {
      $cat_id = $perma_cat['category'];
      $category = get_category($cat_id);
    } else {
      $categories = get_the_category();
      $category = $categories[0];
    }
    $category_link = get_category_link($category);
    $category_name = $category-&gt;name;  
  ?&gt;    
  
    &lt;a href="&lt;?php echo $category_link ?&gt;"&gt;&lt;?php echo $category_name ?&gt;&lt;/a&gt; &lt;span class="ion-ios-arrow-right"&gt;&lt;/span&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Can not find much documentation about this at the moment. Any advise how to improve?</p>