Show Category’s Name or Slug using PHP

Hey! I have simple code for show only category’s name or slug name. So use given code on your website and show any one category’s name/slug.

How to To

Below one php code for show only category’s name name. and another code have showing only category’s name. Use which you have useful.

Show Category’s Slug Only

<?php
$cat = get_the_category();
$parentCatName = get_category($cat[0]->parent);
if ($cat[0]->category_parent){
echo $parentCatName->slug;
}
else {
echo $cat[0]->slug;}
?>

Show Category’s Name Only

<?php
$cat = get_the_category();
$parentCatName = get_cat_name($cat[0]->parent);
if ($cat[0]->category_parent){
echo $parentCatName;
}
else {
echo $cat[0]->cat_name;}
?>

Use any one code on your WordPress theme or use dynamic breadcrumbs code, when you like to make breadcrumbs schema markup.

Thanks for visiting.