 <p>Do this:</p> <pre><code>$cats = get_the_category(); if(count($cats)){ $cat = $cats[0]; $cat = sprintf('&lt;a href="%s" id="cat-%s"&gt;%s&lt;/a&gt;',get_category_link($cat-&gt;cat_ID), $cat-&gt;cat_ID, $cat-&gt;cat_name ); } </code></pre>