Display current category title on category page

Using the following code in a category template, but instead of showing the current category page that I am on, it displays the first category of the first post. For example on Food category page it should say Food, but instead it says Desserts because the first post's category is desserts. Here is the site http://theveganproject.ca/wp/category/food/

add_action ( 'genesis_before_content', 'sk_show_category_name' );
function sk_show_category_name() {
$category = get_the_category();
if (is_category()) {
    echo 'div id="cat-name"' . $category[0]-cat_name . '/div';
}
}

Topic php genesis-theme-framework categories Wordpress

Category Web


You can use single_cat_title('' , true ) this function and add those parameters to removed the prefix.


On a category page, you can use the function single_cat_title(), or the more generic single_term_title(). These functions pull from the global $wp_query object, via get_queried_object().

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.