How to show category name by category id in wordpress
Here is will show you some way to get category name and link from category ID
/// Category link from category Name
// Get the ID of a given category
$category_id = get_cat_ID( 'Category Name' );
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>
Category Name
WordPress – Get Category Link By Category Id
echo get_category_link( "category_id_here" );
?>
WordPress – Get Category name By Category Id
Yellow color color code some shows a error "Catchable fatal error: Object of class stdClass could not be converted to string in ..."
if showing Catchable fatal error: then use bellow for category name
$cat=1;
$yourcat = get_category($cat);
if ($yourcat) {
echo '
}
?>
/// Category link from category Name
// Get the ID of a given category
$category_id = get_cat_ID( 'Category Name' );
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>
Category Name
WordPress – Get Category Link By Category Id
echo get_category_link( "category_id_here" );
?>
WordPress – Get Category name By Category Id
Yellow color color code some shows a error "Catchable fatal error: Object of class stdClass could not be converted to string in ..."
if showing Catchable fatal error: then use bellow for category name
$cat=1;
$yourcat = get_category($cat);
if ($yourcat) {
echo '
' . $yourcat->name . '
';}
?>