Add Category Title to Single Post

Supplemental 66 views
0 Flares 0 Flares ×

When trying to show only the first categories name use:

$category = get_the_category($post->ID);
echo $category[0]->cat_name;

If you want to make it a link use:

$category = get_the_category($post->ID);
echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';

Note that this code will only work within the loop.

For Reference:

Add Category Title to Single Post

Provided by: Tiaan Swart
Posted in Wordpress


Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.


Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×