WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/widget categories args

Contents

Description

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

Examples

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.

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;
}

add_filter( 'widget_categories_args', 'widget_categories_args_filter', 10, 1 );

Change Log

Source File

Related

This page is marked as incomplete. You can help Codex by expanding it.