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?


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()

| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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