title: Wordpress Primary Category
body: <p>I recently needed to change my permalink structure in Wordpress.  However the change caused all my social sharing counters to reset.  I found this great script which I modified below, <a href="http://encosia.com/preserving-social-sharing-counters-through-a-url-change/" rel="nofollow">http://encosia.com/preserving-social-sharing-counters-through-a-url-change/</a>.  I rewrote it so it would remove the %poste-id% at the end of the url on older posts.</p>
  
  <p>The problem is that for the most part this works, however I need it to call the permalink category not the first category in the get_the_category(); array.  Is there anyway I can pull this info, or modify this script to work that way?  This is also being used in the loop.  Thanks!!</p>
  
  <pre><code>    &lt;?php
        $url_change_id = 68135;
        $postid = $post-&gt;ID;
        $category = get_the_category();
        $slug = $post-&gt;post_name;
        $permalink_url = get_permalink();
  
       if (intval($postid) &lt; $url_change_id) {
          $url_date_prefix = "/" . $category[0]-&gt;category_nicename .
                             "/" . $slug .
                             ".html";
  
          $sharing_url = str_replace($permalink_url,
                                     "http://website.com" . $url_date_prefix,
                                     $permalink_url);                        
  
        } else {
            $sharing_url = get_permalink();
  
       }
      ?&gt;
  
      &lt;?php echo $sharing_url; ?&gt;
  </code></pre>