How to display wp_list_categories on div instead of li?

You can specify the style argument as something other than the default (which is list) and it won’t wrap the output in a <li>. You can then wrap it in a <div> yourself.

Combine it with the echo argument if you need to check that the list isn’t empty. Example:

$args = array(
    'taxonomy'           => 'product_category',
    'hide_empty'         => 0,
    'orderby'            => 'name',
    'order'              => 'ASC',
    'show_count'         => 0,
    'use_desc_for_title' => 0,
    'title_li'           => 0,
    'style'              => '',
    'echo'               => false,
);
$categories = wp_list_categories($args);

if ( $categories ) {
    printf( '<div class="col">%s</div>', $categories );
}

Leave a Comment