1

I need to add the "All Categories" item to the default WP categories widget.

I can see that there's a filter that I can hook into in the core (line 485 default-widgets.php).

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

I've written the following function, but I must have something wrong as it's not adding the all categories item to the list.

// Add "All Categories" to categories widget
function add_all_categories_to_widget($cat_args) {
    $cat_args['show_option_all'] = 'yes';
    return $cat_args;
}
add_filter('widget_categories_dropdown_args', 'add_all_categories_to_widget');

Can anyone fill me in on what I've got wrong?

Thanks!

2 Answers 2

1

Sorry, I was just hooking into the wrong filter. My add_filter should have hooked into widget_categories_args not widget_categories_dropdown_args.

0

Just to expand on Gus's answer so that there's a full code snippet for whoever searches for it.

You need to hook into the widget_categories_args filter like this:

add_filter('widget_categories_args', 'add_view_all_to_categories_widget');
function add_view_all_to_categories_widget($args) {
    $args['show_option_all'] = 'View All';
    return $args;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.