Imagine you put a link in your WordPress post, for example to https://green.example
. You also set a link to https://red.example
and to https://yellow.example
. I would like to make it such that depending on the target URL of a link, a CSS class is automatically assigned to the link.
For example https://green.example
should be assigned the class "green", https://red.example
the class "red" and so on.
It should be definable for which links these classes should be assigned, not only for exact URLs (like https://green.example/example/hello.php
), but also by rules like "for all URLs starting with https://green.example
*".
Does anyone know how this can be done in a performance-saving way? Is JavaScript mandatory or can it be done with a WordPress function?
This function should ideally apply to all links, so not only within a post, but also if you use, for example, additional fields through ACF (Advanced Custom Fields).