Unfortunately there is no filter allowing to modify the “Show all” link directly or to add any class to this item:
$output .= "<li class="cat-item-all"><a href="https://wordpress.stackexchange.com/questions/331852/$posts_page">$show_option_all</a></li>";
But there is a wp_list_categories
at the end of function that allows you to modify all the output. Here’s a filter that will highlight “Show all” option if no current_category
is set and we’re not visiting any term from given taxonomy.
function wp_list_categories_highlight_all( $output, $args ) {
if ( array_key_exists( 'show_option_all', $args ) && $args['show_option_all'] ) {
if ( ! array_key_exists( 'current_category', $args ) || $args['current_category'] ) {
if ( is_category() || is_tax() || is_tag() ) {
if ( ! array_key_exists( 'taxonomy', $args ) ) {
$args['taxonomy'] = 'category';
}
$current_term_object = get_queried_object();
if ( $args['taxonomy'] !== $current_term_object->taxonomy ) {
$output = str_replace( "class="cat-item-all"", "class="cat-item-all current-cat"", $output );
}
} else {
$output = str_replace( "class="cat-item-all"", "class="cat-item-all current-cat"", $output );
}
}
}
return $output;
}
add_filter( 'wp_list_categories', 'wp_list_categories_highlight_all', 10, 2 );