I have an ACF Text Area field (2 actually) on my clients WordPress site that will contain a list. The client wants this to output as bullet points on the front end.
I am relatively new to JS so trying to work out how exactly to do this!
I found this – https://www.advancedcustomfields.com/resources/acf-format_value/ – from ACF in terms of adding formatting to certain fields, so have worked out how to add the code to the fields! However, I am struggling to figure out what coding to put in the middle to get each <br>
to add a new <li>
instead…
function my_acf_format_value( $value, $post_id, $field ) {
$my_acf_format_value = explode("n", $value);
echo '<ul>';
echo '<li>' . implode( '</li><li>', $value) . '</li>';
echo '</ul>';
}
add_filter('acf/format_value/name=averetourism_tour_included', 'my_acf_format_value', 10, 3);
add_filter('acf/format_value/name=averetourism_tour_to_bring', 'my_acf_format_value', 10, 3);
This is being implemented on the fields, but isn’t outputting any of the data.
Any help would be greatly appreciated!!!
4
Answers
You can add this style
list-style: circle;
toul
. check below code.This would work, you need to use return $value instead of echo
Despite the nice attempts it is never a good idea to output (
echo
) directly in the filter function. It will screw with the difference betweenthe_field()
andget_field()
.Instead, you’d like to do this
Tested with ACF 1.3.5 WP 6.0.2 PHP 8.1.5
(and yes the
</li>
is optional)