Edit the_category (); for a hierarchical display

For my wp theme I want to use the categories as tags on my posts. Example:

The problem is that the category in red must always be the parent and in gold the child.

Except that returns the categories to me in alphabetical order and not in hierarchical order, so sometimes I end up with the child in red and the parent in gold ...

Knowing that I would only use 2 categories per posts so 1 = the parent and 2 = the child

Do you have a solution?

Topic functions hierarchical tags php categories Wordpress

Category Web


You could assign the post only to the child category, and call the function like so:

the_category( ' ', 'multiple' );

This will output (notice the whitepsace between the anchor tags):

<a href="https://example.com/category/parent/">parent</a> <a href="https://example.com/category/parent/child/" rel="category tag">child</a>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.