Skip to main content


public function array_to_ul( $array, $class = '' )

This method takes an indexed array and builds the HTML for an unordered list, with each array value having its own list item.

Only Pass Trusted Input

Please be aware that $array is first passed through the maybe_unserialize() function (to support passing serialized post meta to the method). The contents of each array index are passed through esc_html(), and then the format_tags() method (allowing for basic content formatting without supporting raw HTML)


  • $array
    (mixed) (required) An indexed array or serialized indexed array to convert into an unordered list.
  • $class
    (string) (optional) A CSS class for the unordered list.


(string) If that passed value for $array is a valid array and is not empty, this method returns the html markup for an unordered list, with each processed value of the passed array wrapped in <li>...</li>. If the provided value for $array is not an array, or is empty, the method returns an empty string.


The following code...

$my_array = array( 'one', 'two', 'three' );
$this->html .= $this->array_to_ul( $my_array, 'some-numbers' );

Would add the following HTML (formatted for legibility here, returned as single line in practice)...

<ul class="some-numbers">


  • The $class argument was added in v1.1.2
  • Format tag support was added in v1.1.2