Skip Navigation

[Resolved] Icons in front of taxonomy filter text

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Waqar 2 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2090397
example button.png

Tell us what you are trying to do?
I have a bunch of buttons filtering a view using "wpv-control-post-taxonomy", custom styled with css. I want to add a icon in front of taxonomy text coming from a custom field image. Is that possible and how?

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-control-post-taxonomy

Is there a similar example that we can see?
See example image

What is the link to your site?
hidden link

#2091251

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

I'm afraid, there is no built-in feature available to achieve this so it will require some custom code and workaround.

Can you share a link to an example image file that you're planning to use as an icon?

regards,
Waqar

#2091423
noun_education_3998793.png

for example a icon from here in svg
hidden link

#2091433
noun_education_3998793.png

for example a icon from here in svg:
hidden link

#2092537

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

Assuming that you've already added support for SVG images in WordPress ( ref: hidden link ), you can add a new image type term field for your taxonomy terms. For this example, suppose the slug of that term image field is "category-image".

You can get that term's image URL, using the Types Fields API shortcode like this:
( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/#image )


[types termmeta='category-image' output='raw' term_id='123456'][/types]

Note: You'll replace 123456 with the actual term's ID from where you'd like to get the term image URL.

You can use these image URLs in the custom CSS code to show them as a background image for the label of the filtering terms like this:
( example screenshot of the result: hidden link )


<style>

.wpv-filter-form .r-button label {
background-position: 14% 50%;
background-repeat: no-repeat;
background-size: 30% !important;
padding: 15px 20px 15px 35px !important;
}

.wpv-filter-form .r-button label[for="post_category-alla"] {
background-image: url(abc.com/wp-content/uploads/2021/06/generic-icon.svg);
}

.wpv-filter-form .r-button label[for="post_category-arbete"] {
background-image: url([types termmeta='category-image' output='raw' term_id='123'][/types]);
}

.wpv-filter-form .r-button label[for="post_category-boende"] {
background-image: url([types termmeta='category-image' output='raw' term_id='456'][/types]);
}

</style>

The above custom CSS code can be included in a new "Fields and Text" block added on the same page as the view, but making sure that it is not inside the view itself.

The first CSS block, prepares all the term filter labels to be shown with a background image.

The second CSS block, add a generic image as a background for the "Alla" label item and you'll replace 'abc.com/wp-content/uploads/2021/06/generic-icon.svg' part with your own generic icon's URL.

The third and fourth CSS blocks, add the background images to the "Arbete" and "Boende" items and you'll replace "123" and "456" with their term IDs respectively.

Similar to these two blocks, you can add more CSS blocks for the other term labels as well.

I hope this helps and please let me know if any step is not clear.

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.