Created
December 1, 2020 10:20
-
-
Save xlawok/5ea1eab8bb389f118dd08f28864ba1be to your computer and use it in GitHub Desktop.
Wordpress add class to category wp_list_categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add class to wp_list_categories | |
// if category has a children add cat-parent class | |
add_filter( 'category_css_class', 'add_class_to_category', 10, 4); | |
function add_class_to_category($css_classes, $category, $depth, $args) { | |
$children = get_terms( $category->taxonomy, array( | |
'parent' => $category->term_id, | |
'hide_empty' => false | |
) ); | |
// print_r($children); // uncomment to examine for debugging | |
if($children) { // get_terms will return false if tax does not exist or term wasn't found. | |
// term has children | |
$css_classes[] = 'cat-parent'; | |
} | |
return $css_classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment