apply_filters( 'widget_categories_args', array $cat_args, array $instance )

Filters the arguments for the Categories widget.


$cat_args array
An array of Categories widget options.
$instance array
Array of settings for the current widget.

Top ↑

More Information

This filter is used by the default “WordPress Widget: Categories” before it passes arguments to the wp_list_categories() function.

Top ↑


File: wp-includes/widgets/class-wp-widget-categories.php. View all references

wp_list_categories( apply_filters( 'widget_categories_args', $cat_args, $instance ) );

Top ↑


Version Description
4.9.0 Added the $instance parameter.
2.8.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    Example migrated from Codex:

    To hide some categories create a filter function in your functions.php file and hook it to the widget_categories_args filter. In this function, add the exclude parameter to the arguments list. Currently, in Version 3.3.2, the exclude parameter is not provided, but for future compatibility you should decide how you want to handle an already existing exclude parameter.

    add_filter( 'widget_categories_args', 'widget_categories_args_filter', 10, 1 );
    function widget_categories_args_filter( $cat_args ) {
    	$exclude_arr = array( 4 );
    	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;

You must log in before being able to contribute a note or feedback.