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 have the menu link per default when using my custom menus, and in my functions.php document I have this:

function home_page_menu_args( $args ) {
    $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );

The thing is, in the custom menu options > pages I have this: "No items." So not sure what's going on, it was working in other websites but not in this one, any idea?

share|improve this question
2  
Do you have any pages created? –  Chip Bennett Oct 2 '13 at 15:51
    
I just created some pages and they appeared normally, still nothing about the home page –  Arturo Oct 2 '13 at 19:26
    
Is wp_nav_menu() displaying a custom nav menu, or a fallback menu? If a fallback menu, is it wp_page_menu(), or a custom fallback? –  Chip Bennett Oct 2 '13 at 19:38
add comment

1 Answer

up vote 0 down vote accepted

First, I'll assume that you have custom nav menus properly configured:

  1. register_nav_menus() in functions.php, to define theme_location values
  2. wp_nav_menu() calls in the template, with theme_location called in the args array
  3. Custom nav menus defined in the admin
  4. Custom nav menu(s) assigned to Theme Locations

If that's the case, then the issue is that you're using the wrong filter. The wp_page_menu_args filter is applied inside of wp_page_menu(), which is the default callback for wp_nav_menu() when no menu is assigned to the indicated theme_location.

The output of wp_nav_menu() applies its own filter: wp_nav_menu_args. So you'll need to hook your callback into that filter as well:

function home_page_menu_args( $args ) {
    $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );
// Hook into wp_nav_menu
add_filter( 'wp_nav_menu_args', 'home_page_menu_args' );

That way, the show_home arg will return true for both wp_page_menu() output and for wp_nav_menu() output.

Be careful with wp_nav_menu(), though; if the user adds a home link to the custom menu, then two home page links will be displayed in the rendered menu.

share|improve this answer
    
Thanks so much Chip! –  Arturo Oct 3 '13 at 20:24
add comment

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.