get_cat_name() WordPress Function

The get_cat_name() function is used to get the name of a category from its category ID.

get_cat_name( int $cat_id ) #

Retrieves the name of a category from its ID.


Parameters

$cat_id

(int)(Required)Category ID.


Top ↑

Return

(string) Category name, or an empty string if the category doesn't exist.


Top ↑

Source

File: wp-includes/category.php

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


Top ↑

Changelog

Changelog
VersionDescription
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.