Automatically listing authors and categories in custom menu

Hi guys,

Using Foxaii’s example I was able to add a list of authors to the main menu (working fine), but once I tried to do the same with categories, they get listed outside the main ul. Here’s the working code I’m using for Authors, and for Categories.

Any idea why the second one doesn’t echo the list inside the dropdown ul? Here you can see a working example.

function add_last_nav_item($items, $args) {
if (!is_admin() && $args->theme_location == 'primary_navigation') {
$items .= '<li><a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="#">Autoren <b class="caret"></b></a><ul class="dropdown-menu"><li>' . wp_list_authors('show_fullname=1&optioncount=0&exclude_admin=0&orderby=post_count&order=DESC&number=8&echo=0') . '</li></ul></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_last_nav_item', 10, 2 );

And the categories:

function add_last_nav_item_categories($items, $args) {
if (!is_admin() && $args->theme_location == 'primary_navigation') {
$items .= '<li><a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="#">Kategorien <b class="caret"></b></a><ul class="dropdown-menu"><li>' . wp_list_categories('show_count=0&exclude=3&depth=-1&title_li=&use_desc_for_title=0&child_of=7') . '</li></ul></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_last_nav_item_categories', 10, 2 );

By default wp_list_categories will echo the results. As you did with the first function, you will need to set echo=0 in the args to return the list instead.

1 Like

Thanks Chriscarr!! I totally missed that arg when I made copy/paste… Cheers!