get_cat_name( int $cat_id ): string

Retrieves the name of a category from its ID.

Parameters

$cat_idintrequired
Category ID.

Return

string Category name, or an empty string if the category doesn’t exist.

Source

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;
}

Changelog

VersionDescription
1.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.