get_cat_name

The timeline below displays how wordpress function get_cat_name has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Retrieves the name of a category from its ID.
 *
 * @since 1.0.0
 *
 * @param int $cat_id Category ID.
 * @return string Category name, or an empty string if the category doesn't exist.
 */
function get_cat_name($cat_id)
{
    $cat_id = (int) $cat_id;
    $category = get_term($cat_id, 'category');
    if (!$category || is_wp_error($category)) {
        return '';
    }
    return $category->name;
}

WordPress Version: 3.7

/**
 * Retrieve the name of a category from its ID.
 *
 * @since 1.0.0
 *
 * @param int $cat_id Category ID
 * @return string Category name, or an empty string if category doesn't exist.
 */
function get_cat_name($cat_id)
{
    $cat_id = (int) $cat_id;
    $category = get_term($cat_id, 'category');
    if (!$category || is_wp_error($category)) {
        return '';
    }
    return $category->name;
}