Link To Child Category For A Post

I’m trying to display a link to just the child category on a WordPress post. For instance if the category for a post is parent > child I want to show a link to just the child category page.

I’m using code from here: Name of last category level for a post

It works perfectly but just prints the child category, how do I go about making it a link tot he child category?

$allCat = get_the_category();
$lastCat = array_reverse($allCat);
echo $lastCat[0]->name;

Read more here:: Link To Child Category For A Post

Leave a Reply

Your email address will not be published. Required fields are marked *