WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like get_the_category_list to only display one or two categories instead of all the categories associated with the post. Haven't been able to find any results.

<?php echo get_the_category_list(); ?>

Any help would be appreciated

share|improve this question
up vote 2 down vote accepted

Quick idea would be to pass some simple separator like comma and cut from the start of result till it.

But I think that if you want better control on output it would make more sense to use level deeper get_the_category() function and build markup yourself.

share|improve this answer

This worked. Found in http://codex.wordpress.org/Function_Reference/get_the_category

$category = get_the_category(); 
echo $category[0]->cat_name;
share|improve this answer

If you want to limit get_the_category to any number you can use break;

For example if you want to limit echoing a category + link to show say only 5 categories.

     $i = 0;
      foreach((get_the_category()) as $cat) {
        echo '<a href="'.get_category_link($cat->cat_ID).'"> | ' . $cat->cat_name . '</a>';
        if (++$i == 5) break;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.