How To Get Parent Category Name In WordPress

Last updated on April 17th, 2019 at 09:21 am

It is not difficult to get the name using the build in function from WordPress. You may use this for build your own plugin or list out the related post using the category data from the parent category.

Here is the PHP Code that can display out the name of the parent category.

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

Tags:

1 thought on “How To Get Parent Category Name In WordPress”

Comments are closed.

Discover more from Juzhax Technology

Subscribe now to keep reading and get access to the full archive.

Continue reading