excluding categories from the category widget

I want to exclude certain categories from the standard category widget in wp

In my functions I put this which I got from the codex but it’s not working at all. I also tried this

Read More

Am I missing something

function exclude_widget_categories($args)
  {
    $exclude_arr = array( 3,5,17);
    if( isset( $cat_args['exclude'] ) && !empty( $cat_args['exclude'] ) )
        $exclude_arr = array_unique( array_merge( explode( ',', $cat_args['exclude'] ), $exclude_arr ) );
    $cat_args['exclude'] = implode( ',', $exclude_arr );
    return $cat_args    
  }
  add_filter('widget_categories_args','exclude_widget_categories', 10, 1);

Related posts

1 comment

  1. The variable is wrong, in the parameter is $args, but you’re using $cat_args in function.

    Should be:

    function exclude_widget_categories( $cat_args ) {}
    

Comments are closed.