Is there any way to remove the commas from the checkbox and multiselect custom field output?
I’m using a checkbox list to select words I want to add as class names on an HTML element.
For instance, if I check web and print, my element will have class=“web print”. Right now it is class=“web, print”.
Hi, you don’t need any additional components installing.
First of all, alter the template preferences and enable PHP.
Then, add the following to the top of the template:
<?php
$classes = '{custom_field_name}'; // assigning the custom field value to a PHP variable
$classes = str_replace(",", "", $classes); // replacing the commas with nothing from the classes variable
?>
Be sure to change {custom_field_name} for the name of your actual custom field name.
Then, add the following to your HTML:
That should work.
If not, come back and let me know what happened (or didn’t happen, as the case may be).