Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get the list of authors to automatically appear on the main navi (without having to manually add them one by one as they are created).

So far I added this on my functions.php, but no luck:

function wps_nav_authors ( $items, $args ) {
if ( $args->theme_location == 'Primary') {
$items .= '<li><a href="#">Authors</a><ul class="sub-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', 'wps_nav_authors', 10, 2 );

I've also tried with simpler codes just to see if I was able to add a random li element to the menu, but also without result. I tried with:

add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
function your_custom_menu_item ( $items, $args ) {
if ($args->theme_location == 'Primary') {
$items .= '<li>Show whatever</li>';
}
return $items;
}

Also, my main menu is called Primary.

Any ideas? Thanks!

share|improve this question

1 Answer 1

Just out of luck, I tried adding the code to nav.php instead of the custom.php (which contains the functions.php in the Roots.io theme), and it worked like a charm.

Also, being based on Boostrap 3, I had to add some classes and attributes for the dropdown to work. Here's the final code, if anybody else might need it:

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="#">Authors <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 );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.