1

This function adds a home link into my nav menu, but it is added to 3 other menus I am using as well. I don't quite understand where to add code to only display in my primary nav.

function my_page_menu_args( $args ) {
    $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'my_page_menu_args' );
3
  • Couldn't find an answer so I am now hiding the other home links with css.
    – Drai
    Commented Jul 26, 2011 at 15:36
  • What function you use to display menus? I guess wp_page_menu right?
    – Mamaduka
    Commented Sep 24, 2011 at 8:56
  • Yep the following code <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
    – Drai
    Commented Sep 30, 2011 at 1:20

1 Answer 1

1
function my_page_menu_args( $args ) {
    if($args['theme_location'] === 'primary')
        $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'my_page_menu_args' );

The $args array also contains the theme location, so you can filter on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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