ACF Template Builder

Changing shortcode output

All field-types are handled using WP's hook system. You can add filters to change the output by targeting the specific field-type.

remove_filter( 'bbacf/helpers/get_acf_field/type=checkbox' , 'bbacf_helpers::shortcode_acf_return_checkbox' ,10 );
add_filter( 'bbacf/helpers/get_acf_field/type=checkbox'		, 	'return_custom_acf_checkbox' , 11, 5 );

function return_custom_acf_checkbox ( $string , $field_object , $value , $atts = null , $postid = null ) {

            // get the correct fieldname for version 4 or 5 of acf
            $get_fo = bbacf_helpers::$fr[ bbacf_acf_version() ];

            if ( $field_object[ 'type' ] == 'text' ) return $string . $value ;

            // determine return-value of checkbox

            switch ($field_object[ $get_fo ] ) {
                case 'array':
                    $selected_values = '';

                    foreach ($field_object[ 'value' ] as $choice ) {

                        if ( in_array( $choice , $value ) ) {
                        	$selected_values .= '<div style="clear:both;"><div style="background-color:' . $choice[ 'label' ] . ';width:24px;height:24px;float:left;margin-right:5px;border:1px solid #f1f1f1;"></div>' . $choice[ 'label' ] . '</div>';
                        };

                    }

                    return $string . $selected_values;

                break;
                default:

                    return $string . join( $value, ', ' );

                break;
            }

	return $string;
}

Default display:

acf-shortcode-out-1

Display after changing the filter:

acf-shortcode-out-2