I'd like to add code to my functions.php to intercept all calls to wp_list_categories() AND the_category() so that it excludes "uncategorized" and any children of "uncategorized" (OR cat_id 1). I'd also like to limit the number of words returned in the "title" attribute of each list item anchor. Currently the default is to set $cat_args['use_desc_for_title'] = 1; but It does not appear it's possible to insert that into the exclusions filter below.

I'm using the code below which effectively removes the unwanted categories from the lists that use wp_list_categories, however, it does not remove them from lists derived from the_category...

function my_list_terms_exclusions($exclusions,$args) {
  $children = implode(',',get_term_children(1,'category'));
  $children = (empty($children) ? '' : ",$children");
  return $exclusions . " AND (t.term_id NOT IN (1{$children}))";
add_filter('list_terms_exclusions', 'my_list_terms_exclusions', 10, 2);?>
  • 1
    Why not just get rid of uncategorized ? Make some other category default one, then you can delete uncategorized. Much less hassle. – Rarst Jan 11 '11 at 13:30

I was finally able to figure this one out... Although I have to set the filter directly on the widget_categories_args method, so it does take two filter statements to do it.

function my_categories_filter($cat_args){
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['exclude'] = 1;
    $cat_args['use_desc_for_title'] = 0;
    return $cat_args;

add_filter('widget_categories_args', 'my_categories_filter', 10, 2);
| improve this answer | |
  • @philip: you would add each one to the exclude list (its an array) – Scott B Mar 12 '11 at 20:15

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.