WordPress Code Snippets

A fresh mix of code snippets and tutorials

Display category name in WordPress

81

Here are two snippets for displaying the category name and displaying the category link in WordPress.

To display the name of the first category:

<?php $cat = get_the_category(); echo $cat[0]->cat_name; ?>

0 displays the first category, so 1 will display the second category, and so on.

To display a list of links to each category:

<?php the_category(', '); ?>

The comma ', ' serves as a separator when the post is included in more than one category.

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!