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?
![](https://itnursery.com/wp-content/uploads/2022/05/1653662503_apple-touch-icon@2.png)
1 Answer
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()