Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have found this code here.

$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;

This returns something like this (5).
I want to remove () and show only 6.

share|improve this question

closed as too localized by kaiser, toscho Jun 24 '13 at 15:32

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

up vote 0 down vote accepted

This should make you good to go:

$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;

The ( and ) were in the code.

And if you only want to show 6 categories replace the $args part with:

$args = array(                 
  'hide_empty' => FALSE,                 
  'title_li'=> __( '' ),                 
  'show_count'=> 1,             
  'echo' => 0,
  'number' => 6
);
share|improve this answer
    
Thank you @Mike Madern.This really works better. –  ashraf Jun 27 '13 at 13:37
    
If this answer helped you out, please accept it as an answer to close this question :-) –  Mike Madern Jun 27 '13 at 14:22

You can do this with a filter on wp_list_categories.

function strip_parens_from_list_cat_wpse_104044($list) {
  $pattern = '|\(([0-9]*)\)|';
  return preg_replace($pattern,'$1',$list);
}
add_filter('wp_list_categories','strip_parens_from_list_cat_wpse_104044');

Put the function definition-- the part above-- in functions.php or a plugin file then use it like:

add_filter('wp_list_categories','strip_parens_from_list_cat_wpse_104044');
$links = wp_list_categories($args);
remove_filter('wp_list_categories','strip_parens_from_list_cat_wpse_104044');

Or if you want this to operate globally, put add_filter('wp_list_categories','strip_parens_from_list_cat_wpse_104044'); in functions.php as well.

share|improve this answer

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