Category urls for child categories of a specific parent by ID used in the loop Copy
Description
This code will create a category url for child categories of a specific parent by ID used in the loop. In this example change 8 to the id of the parent that you want to show children for.
This code will create a category url for child categories of a specific parent by ID used in the loop. In this example change 8 to the id of the parent that you want to show children for.
PHP Source Code
<!--Get Child Category URLs start-->
<?php
foreach((get_the_category()) as $childcat) {
if (cat_is_ancestor_of(8, $childcat)) {
echo '<a href="'.esc_url( $category_link ).'" title="'.esc_attr($cat->name).'">'.$childcat->cat_name.'</a>';
}}
?>
<!--Get Child Category URLs End-->