I am trying to hack the default categories widget from wordpress. I have the categories displaying the way I want but I am having trouble editing the output. The widget shows the number of posts in each post which is what I want, but it also displays the number in parenthesis. I don’t want that. I know how to get rid of them but I can’t seem to make it work. I tried like so
$cat_args['title_li'] = '';
$list = wp_list_categories(apply_filters('widget_categories_args', $cat_args));
$list .= str_replace('(', '<span class="number">', $list);
$list .= str_replace(')', '<span class="number">', $list);
echo $list;
It just continues to display the categories the same way. I don’t understand why it’s not echoing the list. I am using the code for the categories from the default-widgets.php file in the wp-includes folder.
wp_list_categories
echoes output by default, yourstr_replace
isn’t working because nothing was assigned to$list
.I’ve run into this situation too, and ended up duplicating the built in List Categories widget, and customized it to fit my needs. I left a couple variations of the $replacement regex commented out in the code.