Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Try removing the ‘sanitize_text_field’ callback from the ‘pre_term_name’ filter (priority 10). You should add back in some sort of sanitation that allows HTML.

    What sort of HTML are you trying to add? HTML should typically be applied just before output and not stored with terms in the database. Allowing HTML in terms could lead to other problems. This is not a great approach. If I understood what you are trying to do, I may be able to suggest a better alternative.

    Thread Starter Samnabz

    (@samnabz)

    Hi bcworkz,

    Thank you for the prompt and detailed response.

    I am wanting to use Font Awesome icons in the category name – e.g <I class=”fa fa-icon”></I> Category Name Here.

    Do you have another solution for this?

    Thread Starter Samnabz

    (@samnabz)

    I should add, that I am wanting to use a different icon for each category. So simply calling a predefined icon before each cat name will not suffice.

    Moderator bcworkz

    (@bcworkz)

    You could create a template tag function that outputs the appropriate HTML, tailored to whatever the current category is. Then call this tag from any templates where you want the icon with the category name.

    The function would be mostly a switch/case structure where each case is a category slug. The subsequent code would echo out the necessary HTML.

    Another approach is to identify all functions called by templates to output categories. There are likely filters for these functions that you can hook and insert appropriate HTML into the return values. Your filter callback would also use a switch/case structure much like the template tag idea.

    Either concept would be fairly straight forward for existing categories. Things get more complicated when new categories are added and the appropriate icon needs to be associated with the new category. You can add a field to the categories admin screen to accept this input. I’m not sure where the best place is to store this data, but I’m sure a solution is possible.

    If the icon to category relationship is stored on a table somewhere, then instead of a switch/case structure, the above mentioned functions would be making a DB query to determine the correct output.

    Thread Starter Samnabz

    (@samnabz)

    Hi bcworkz,

    I tried various methods, but to no avail..

    What I ended up doing was using a plugin to enable HTML in the category description field. I then entered the coding to display an icon and echoed the description before the category name.

    Thank you for all your help / time anyway. It was much appreciated! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post Category Name – Allow HTML?’ is closed to new replies.