0

If I set 'echo' parameters value to 'true':

<?php if( has_nav_menu( 'primary-menu' ) ) {
                    wp_nav_menu( $menuParameters = array( 
                        'theme_location'  => 'primary-menu',
                        'container'       => '', 
                        'container_class' => false,
                        'container_id'    => false,
                        'menu'            => 'Primary',
                        'menu_id'         => 'test',
                        'menu_class'      => 'nav navbar-nav navbar-right',
                        '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 (array('theme_location' => 'primary-menu'));

                    } ?>

I get an output of:

<ul id="test" class="nav navbar-nav navbar-right">
 <li class="current-menu-item"><a href="http://localhost/test/">Home</a></li>
 <li><a href="http://localhost/test/contact/">Contact</a></li>
</ul>
<ul id="menu-primary" class="menu">
 <li class="current-menu-item"><a href="http://localhost/test/">Home</a></li>
 <li><a href="http://localhost/test/contact/">Contact</a></li>
</ul>

The first one is the desired result and the last one is WP default output which is a pain. Any ideas on how to get rid of it by altering my array?

2
  • 2
    because you are calling "wp_nav_menu" two times.
    – M-R
    Commented Jan 26, 2015 at 13:48
  • 2
    Aargh, it's time for a break. Thank you @M-R
    – Laniakea
    Commented Jan 26, 2015 at 13:52

1 Answer 1

3

You have two calls to wp_nav_menu function

<?php if( has_nav_menu( 'primary-menu' ) ) {
    wp_nav_menu( $menuParameters = array( 
        'theme_location'  => 'primary-menu',
        'container'       => '', 
        'container_class' => false,
        'container_id'    => false,
        'menu'            => 'Primary',
        'menu_id'         => 'test',
        'menu_class'      => 'nav navbar-nav navbar-right',
        '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'          => ''

        ) ); 

    // Following is outputing second menu html
    //wp_nav_menu (array('theme_location' => 'primary-menu'));

} ?>

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.