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 try to add the home button in a specified WordPress menu (I have 2) and it's not working at all.

This is my code:

<?php wp_nav_menu(array('theme_location' => 'primary', 'show_home' => $args['show_home'] = true)); ?>

Calling the 'global $args;' didn't work. What I'm doing wrong?

Thanks in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

show_home isn't working for you because there is no show_home argument on wp_nav_menu. You will need to add it using the menu editor in the admin panel, most likely as a custom link.

These are the valid arguments:

$defaults = array(
    'theme_location'  => '',
    'menu'            => '',
    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'menu',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
);

wp_nav_menu( $defaults );

You've likely been given an example that has confused wp_nav_menu with wp_page_menu, which does have a show_home argument

share|improve this answer
    
As an extra note, you could modify items_wrap to include the markup for the first menu item, using home_url() as the URL, but experienced developers would frown upon this –  Tom J Nowell Apr 4 at 17:42
    
Oh I see, thank you! I'm gonna remove the wrong part of that code, then. –  Gerard Apr 4 at 17:43

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.