4

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

10

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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