WordPress.org

Ready to get started?Download WordPress

Forums

wp_nav_menu() does not accept arguments (2 posts)

  1. James Mehorter
    Member
    Posted 3 years ago #

    Hi all. I am creating a custom menu and want the menu to be within <div id="Navigation"> in my theme, but the arguments passed to wp_nav_menu() have no affect on the output. Setting menu_class is the only argument which works to style the output :( Any ideas? Thanks!

    <?php wp_nav_menu( array( 'menu' => 'Masthead Navigation', 'container_id' => 'Navigation' ) ); ?>
    
    Generates the following:
    <div class="menu">
    
    <ul>
            <li class="page_item page-item-4 current_page_item">
              <a href="" title="Home">Home</a>
    
    </ul>
    </div>
  2. James Mehorter
    Member
    Posted 3 years ago #

    So the codex documentation does not say anything about this, but digging in wp-includes > nav_menu_template.php found that if you do not specify the theme_location argument for wp_nav_menus() then none of the container / menu style arguments will work. Below I have documented the process for generating a menu with these args, hopefully it will help someone else!

    In functions.php:
    register_nav_menus( array(
    'primary' => __( 'Masthead Navigation', 'DLLT' ),
    'secondary' => __( 'Footer Navigation', 'DLLT' ),
    ) );

    In wp-admin, assign pages to the menu just registered, then in my header.php to output the menu I used:

    <?php wp_nav_menu( array( 'menu' => 'Masthead Navigation', 'container_id' => 'Navigation', 'theme_location' => 'primary' ) ); ?>

    <div id="Navigation" class="menu-masthead-navigation-container">
        <ul id="menu-masthead-navigation" class="menu">
            <li id="menu-item-23" class="menu-item menu-item-type-post_type">
            	<a href="/support/">Support</a>
            </li>
        </ul>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic