Skip Navigation

[Resolved] I'd like to display images instead of checkbox value

This thread is resolved. Here is a description of the problem and solution.

Problem:
Customer would like to display pictures (icons), instead of checkbox values
Solution:
Checkbox title accepts HTML code, it is possible to customize it as you need and display images for example.
Relevant Documentation:
If this is not working right off the top, you might need to go through this errata and disable the sanitize via hook as described here: https://toolset.com/errata/html-in-toolset-custom-field-labels-is-stripped-when-saving-the-fields/

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 2 replies, has 2 voices.

Last updated by fabriceS 10 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2680450

Hi,

Can you help me to display pictures (icons), instead of checkbox values ?

For a CPT I have a Custom Fields Group in which I have 1 "selected list" and 1 "checkboxes".
For the "checkboxes" (so with multiple choices) I'd like to display icons of the selected boxes instead of their db values.
How can I achieve that ?

Thanks.

#2680509

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

When you're setting up the checkboxes in the custom field screen, you can add html tags to the title, so you can add images with the <img src=""> tag.

Then those will be displayed with the checkboxes.

Just one little setting you have to perform before, it is described here(https://toolset.com/errata/html-in-toolset-custom-field-labels-is-stripped-when-saving-the-fields/):

In Toolset Settings -> Custom Code, add a new code snippet:

• Run mode: Run always
• Run context: WordPress admin
• Content: php

Snippet content:

<?php
/**
* Deactivate the sanitization of custom field and field option labels,
* so that they can contain HTML code.
*
* Note that this is not recommended for sites that don't explicitly need it.
* Disabling sanitization can have undesired security or other ramifications.
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
add_filter( 'types_sanitize_field_labels', '__return_false' );

After the code is added, in the custom code section, select the code you entered and activate it, otherwise everytime you save your titles with the <img> tag, it will get striped from the field.

Please give it a try and let us know.

Thank you,
Mateus

#2680593

Hi Mateus,

Thanks for that. It works now.
However when I display on the front-end I'd like to display icons too.
Is there a way to display the title there instead of the value ? or to be able to enter HMTL code as a value ?

#2680595

It already accept HTML actually.