Sample use case: On the Blog page set a specific background color for all "Nature" category archive labels/links and a different background color for "Flowers" category archive labels/links in the posts grid.
We will cover both static and dynamic cases wherein category-specific colors can either be set in CSS (static) or pulled from a Color-type of custom field for the categories (dynamic).
Sample HTML markups:
To display the linked terms with our custom HTML markup, we can use this dynamic tag as one of the Fields of the Posts element in a Query Loop:
This outputs the categories for the current post in the loop separated by a comma.
The function is going to be set to take 2 parameters: taxonomy (
category is the default) and separator (
, is the default).
In this example, let's use this instead so there is no separator:
Let's define a custom function that takes in the taxonomy and separator as its arguments and returns the term names linking to their archives with the taxonomy slugs as the value of the
Add the following in child theme's
functions.php or a code snippets plugin:
This is a Pro members-only tutorial.
To get full access, login below or sign up for a Pro Account