Add Parent and childs category to body class
-
hello, how add whole category into body class? the code i got from google is
// add parent category class add_filter('body_class','body_class_section'); function body_class_section($classes) { global $wpdb, $post; if (is_page()) { if ($post->post_parent) { $parent = end(get_post_ancestors($current_page_id)); } else { $parent = $post->ID; } $post_data = get_post($parent, ARRAY_A); $classes[] = 'parent-' . $post_data['post_name']; } return $classes; }
But it only return last child category. i’d like to return from parent,child, child of child and so on category. how do i achieve this?
thank you
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Add Parent and childs category to body class’ is closed to new replies.