Post Category Links Ordered by Parent and Child Categories in Bricks

A user asks:

How do I sort term name, it has to be parent category first then the sub-category. The red arrows indicates parent category.

As far as know, there is built-in setting or a filter in Bricks builder to output comma-separated post categories with parent categories at the beginning followed by child categories.

However, we can write a custom function that gets all the categories assigned to the current post, filter them to get parent and child categories as separate arrays, merge these arrays in that order, loop through the combined array and construct the HTML to output category names linking to the corresponding category archive pages.

Then we simply use this function as a dynamic data tag.

This Pro tutorial shows how.

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to 390+ Bricks code tutorials with BricksLabs Pro