Display the category name:

<?php
$category = get_the_category(); 
echo $category[0]->cat_name;
?>

But, If multiple categories, it will show only first category name.

single_cat_title(), its working only in category.php for me.

<?php $current_category = single_cat_title("", false); ?>

false is used when we need to assign value in php variable,

<?php $current_category = single_cat_title("", true); ?>

true is used when we need to display category without echo, first parameter is for prefix for category, the first parameter is only working for true option for me.

Get the category Id:

<?php echo $cur_cat_id = get_cat_id( single_cat_title("",false)); ?>
Advertisements