WordPress menu: automatically add categories

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:

Read More
  • 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 !

Related posts

1 comment

  1. 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 );
    

Comments are closed.