Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * auto add child terms to nav menus
- */
- function custom_walker_nav_menu_start_el ( $item_output, $item, $depth, $args) {
- // filter only taxonomy menu items
- if( $item->type == 'taxonomy' ) {
- // set args
- $args = array(
- 'taxonomy' => $item->object,
- 'child_of' => $item->object_id,
- 'echo' => 0,
- // 'hide_empty' => 0,
- 'show_option_none' => '',
- 'title_li' => ''
- );
- // check for children
- $children = wp_list_categories( $args );
- // if any, append them as a list
- if ( $children )
- $item_output = $item_output . '<ul class="children" >' . $children . '</ul>';
- }
- return $item_output;
- }
- add_filter( 'walker_nav_menu_start_el', 'custom_walker_nav_menu_start_el', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment