The code below works for my posts from Custom Post Type(called Sermon) which is displaying the child category name only with its links.
<?php
$categories = get_the_category();
if ( ! empty( $categories ) ) {
echo '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">Child Category : ' . esc_html( $categories[0]->name ) . '</a>';
}
?>
But it doesn't work when I reuse it for my posts from post type itself(News category). It keeps showing the parent category(News), unless I unchecked it so it displays the child category only(like entertainment, politics, etc.).
Any help would be appreciated. Thanks!