This code enables you to control the order of any taxonomy terms in WordPress including categories, tags and custom taxonomy terms for custom posts types.
The code also shows you how to add any type of separator between terms when there’s more than one term without adding the separator after the last term.
Here’s 3 examples of the output showing the parent term, child of parent term and child of child term with 2 different types of separators including, commas, hyphens, arrows and icons ( dashicons ).
Shows 3 different methods to display taxonomy terms names linked and unlinked for your custom post type, tags or categories. In this case, it works with the portfolio custom post type using portfolio-type for the custom taxonomy.
There’s 2 steps :
- # Copy one of the code snippets from the single-portfolio.php file to your child themes functions file, archive template, taxonomy template of single CPT template depending on where you want your terms to output. You can then swap out the name of the taxonomy with your taxonomy name. The default is portfolio-type.
- # Copy & paste one of the CSS rules to the end of your child themes stylesheet and clear caching.