Thanks for the answer above, I found a solution that allows for even more customisation of the output of wp_list_categories. I'm using this for showing all terms in a taxonomy.
<?php
$args = array(
'taxonomy' => 'place',
'orderby' => 'name',
'style' => 'list',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'title_li' => '',
'exclude' => '28',
'echo' => '0'
);
As opposed to the example above which requires 'style' => 'none', I'm using 'style' => 'list', outputting an unordered list with <li>
and <ul>
tags but no <br />
tags.
Then the PHP command strip_tags
selectively strips all html tags. This would of course also work for stripping the <br />
tag when using 'style' => 'none'.
<?php $variable = wp_list_categories($args); ?>
<?php $variable = strip_tags( $variable, '<a>' ); ?>
<?php echo $variable; ?>
The second parameter in strip_tags
are the allowable tags, i.e. tags that are kept in the code. So it's keeping the <a>
tag to preserve all links, and bingo!
Now the deluxe version allows, for example, to style child terms differently to their parents:
<?php $variable = wp_list_categories($args); ?>
<?php $variable = strip_tags( $variable, '<a><ul>' ); ?>
<?php $variable = str_replace('ul', 'span', $variable); ?>
<?php echo $variable; ?>
Firstly this keep the <a>
tag and the <ul>
tag which always has the class "children". Then it replaces 'ul' with 'span' and the tag will read <span class="children">
. Now all list tags are gone and you're free to add a CSS style for the class "children".