I’m using this code:
$args = array(
'hide_empty' => FALSE,
'title_li'=> __( '' ),
'show_count'=> 1,
);
wp_list_categories($args);
How can i wrap the post count in a span for further styling?
Thanks
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
adding a filter to functions.php of your theme is one possibility:
add_filter('wp_list_categories', 'cat_count_span');
function cat_count_span($links) {
$links = str_replace('</a> (', '</a> <span>(', $links);
$links = str_replace(')', ')</span>', $links);
return $links;
}
this would add the spans to any occurrence of ‘wp_list_categories()’ site wide.
or change your code into:
$args = array(
'hide_empty' => FALSE,
'title_li'=> __( '' ),
'show_count'=> 1,
'echo' => 0
);
$links = wp_list_categories($args);
$links = str_replace('</a> (', '</a> <span>(', $links);
$links = str_replace(')', ')</span>', $links);
echo $links;
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0