get the category wp 1

get the category wp

//get category name foolproof 
echo (!empty(get_the_category($post)) ? get_the_category($post)[0]->name : '');

Here is what the above code is Doing:
1. Get the category of the current post
2. If the category is not empty, get the first category name
3. If the category is empty, return an empty string

Similar Posts