WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible using wp_list_categories set count of post in category in the href?

share|improve this question
It's possible, with some regular expression jiggery pokery. Some variation on this – vancoder Apr 11 '13 at 18:59
+1 for jiggery pokery – Eric Holmes Jan 31 '14 at 20:13

Regular expression jiggery pokery identified:

$categories = wp_list_categories('title_li=&show_count=1&echo=0');
$categories = preg_replace('/<\/a> \(([0-9]+)\)/', ' <span class="count">[\\1]</span></a>', $categories);
echo $categories;
share|improve this answer
nice solution @vancoder, but preg_replace might be a better choice because ereg_replace is deprecated since php 5.3, according to php.net/ereg_replace. – birgire Apr 11 '13 at 19:45
@birgire Excellent point, answer updated. – vancoder Apr 11 '13 at 20:47
Great solution thanks. – Murhaf Sousli Jul 13 '14 at 1:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.