Search code examples
phpwordpresswp-list-categories

Remove parentheses from category counts in wordpress and exclude category


I'm using the following code to remove the parentheses from category counts in Wordpress which works fine however the &exclude=10 to exclude a category no longer works.

<?php
 $variable = wp_list_categories('echo=0&show_count=1&title_li=&exclude=10');
 $variable = str_replace(array('(',')'), '', $variable);
 echo $variable;
?>

Solution

  • $args = array(
        'echo'       => 0,
        'taxonomy'   => 'category',
        'exclude'    => 10,
        'hide_empty' => 1,
        //'parent'     => 0  //uncomment this if you only want top level cats
    );
    $cats = get_categories($args);
    echo '<ul>';
    foreach ($cats as $cat) :
       echo '<li><a href="'.get_category_link( $cat->term_id ).'">'.$cat->name.'</a></li>';
    endforeach;
    echo '</ul>';
    

    WP bug bypassed with different function that essentially does the same thing.