Retrieves the name of a category from its ID.
Parameters
$cat_id
intrequired- Category ID.
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
Version | Description |
---|---|
1.0.0 | Introduced. |
Basic Example
returns the name for the category with the id ‘4’.