Support

Account

Home Forums Front-end Issues Checkbox Shortcode Display as List

Solving

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

    To:
    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:

    <?php
    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!

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

You must be logged in to reply to this topic.