Question

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;
?>
Was it helpful?

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.

OTHER TIPS

The code that works: Make sure it goes into your Functions.php file.

hadd_filter( 'woocommerce_subcategory_count_html', 'wc_filter_woocommerce_subcat_count_html', 10, 2 );
function wc_filter_woocommerce_subcat_count_html( $mark_class_count_category_count_mark, $category ) {
$mark_class_count_category_count_mark = ' <mark class="count">' . $category->count . '</mark>';
return $mark_class_count_category_count_mark;
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top