← Blog

Convert text lines to list items

WordPress1 min read

<?php
  // Get the points from the ACF field
  $points = get_sub_field('points');

  // Add new line to each point
  $points = explode("\n", $points);

  // Now convert to HTML
?>

<ul><?php

  foreach($points as $point) : ?>
    <li><?php echo $point ?></li><?php
  endforeach; ?>

</ul>

Stuck on something like this?

I help businesses and agencies with WordPress, WooCommerce and JavaScript problems, from one-off fixes to ongoing support.