Home Forums Front-end Issues Checkbox Shortcode Display as List


Checkbox Shortcode Display as List

  • Hi,

    I just downloaded this plugin and was wondering how I can change the display format of the checkbox from a comma list into a unordered list?

    Example: Swimming Pools, Water Parks, Resort Style Water Parks

    Swimming Pools
    Water Parks
    Resort Style Water Park

    By the way, I am using the shortcode to display it on the post and not PHP. Thanks in advance!

  • Hi @flyingeagle,

    ACF does not offer any way of overriding this so the best solution would be to create your own custom shortcode to display the value as an unordered list. Copy the following code to your functions.php file:

    function custom_acf_shortcode( $atts ) {
    	// extract attributs
    	extract( shortcode_atts( array(
    		'field'			=> '',
    		'post_id'		=> false,
    		'format_value'	=> true
    	), $atts ) );
    	$value = get_field( $field, $post_id, $format_value );
    	if( is_array($value) )
    		$ul = '<ul>';
    		foreach($value as $val) {
    			$ul .= '<li>' .$val. '</li>';
    		$ul .= '</ul>';
    		$value = $ul;
    	return $value;
    add_shortcode( 'custom_acf', 'custom_acf_shortcode' );

    Then use it as follows: [custom_acf field="field_name" post_id="123"]

    Hope this helps 🙂

  • Hi James,

    Thank you for your reply. I tried the code you provided but when I copied and pasted it into the functions.php, it produced an error at the first line where php is declared.

    I tried it without <?php tag and it didn’t have an error but it didn’t work when I put tried the shortcode on the post. Am I missing something?

    Thanks for assisting!

  • Hello,
    it works!
    Just a quick question: how can I add a class to each

  • ?
    Like this:
    <li class="value">Value</li>


Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Checkbox Shortcode Display as List’ is closed to new replies.