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'm stuck in a rather simple task: to get the category title for the current post, within the loop, to be used in the function (not to be automatically printed). Any ideas?

share|improve this question
what do you mean with 'to be used in the function' ? is this what you want: codex.wordpress.org/Function_Reference/get_the_category – Michael Apr 4 '12 at 21:05
up vote 2 down vote accepted

The function get_the_category() returns an array of category objects. To get the name of the first category, use this:

$categories = get_the_category(); 
$cat_name = $categories[0]->cat_name;

For a list of the properties of the category object, see the documentation on get_the_category()

share|improve this answer
Oh, god. It returned an array.. of course! And I completely forgot to sprint_f it, to make things worse. I'm such a bad programmer sometimes.. thanks for the help! – João Apr 5 '12 at 15:27

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.