1
votes

In Wordpress, i'd like to automatically add categories from custom post types in a submenu item, with respecting the hierarchy.

This is how my menu will look like:

  • Projects
    • Categories
      • Category 1
      • Category 2
        • Subcategory1
        • Subcategory2
      • Category 3
      • ....
    • Other Sub item
      • ItemX
      • ItemY

Any idea on how to automatically add all categories in the menu, under "Categories" item? (It's a menu created in Appearance > Menus) I guess i might use wp_list_categories() but I have no idea where to place this...

Thanks !

1

1 Answers

1
votes

Try this filter

It's a little hacky but i managed to add some stuff into my menus from here

WP nav menu itmes

function wp_nav_menu_items( $items, $args ) {
    if ( "primary" == $args->theme_location ) { //check what menu it is
        //Do Stuff here
    }

    return $itmes;
}

add_filter( wp_nav_menu_items, wp_nav_menu_items );