Skip Navigation

[Resolved] Add images to radio button options

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

Problem: I would like to show a custom field in the wp-admin area that allows admins to select from several predefined images.

Solution: It's possible to use HTML in the label input for each radio field option. So you could include an image tag in the label and it would show up in the backend post editor next to the radio button. You don't have a lot of options for managing the styles in wp-admin, though. See img-tag.png for an example of the post field editor.

This support ticket is created 7 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 3 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#582382

I'm trying to set up a custom field in which content editors could pick one of several logos. Is there a way to integrate image files right into the back end, associating them with values of the radio buttons? If not, I can use text options, but then I'm not sure how to make those text options associate with images for front-end display. Thanks in advance for your help.

#582517
img-tag.png

It's possible to use HTML in the label input for each radio field option. So you could include an image tag in the label and it would show up in the backend post editor next to the radio button. You don't have a lot of options for managing the styles in wp-admin, though. See img-tag.png for an example of the post field editor.

If you would prefer to go with a text label, you could accomplish this with unique icon file names, used as the value for each option of a radio or select field. For example, let's say your images are called "image.png", "document.png", "spreadsheet.png", and so forth, to represent different file type icons. You could set up a radio or select field that includes option values like "image", "document", and "spreadsheet". Then use the value of the custom field to display the correct icon image on the front-end of your site by composing a custom img tag:

<img src="path/to/icon/directory/[wpv-post-field name='your-radio-field-slug'].png" />

This approach requires that all the icon files exist in the same directory on your server.

The wpv-post-field shortcode is one way to access custom field information from a specific post. More info about that shortcode here:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

Let me know if I've misunderstood your request, and I'll be glad to take another look.

#584653

thank you!

#2039957

FYI - as of Types 3.3.4, an additional custom code snippet is required to use HTML in custom field labels like this.

add_filter( 'types_sanitize_field_labels', '__return_false' );

See more information in our erratum post:
https://toolset.com/errata/html-in-toolset-custom-field-labels-is-stripped-when-saving-the-fields/