• Resolved NikiOnTime

    (@nikiontime)


    Hello,
    I’m new to the WP community and I’m trying to build my first theme.
    I’m having problems with the wp_nav_menu function.
    I want to customize the markup that is generated by it but so far I’m failing. I want to change the container to <nav>, to set class=”” and id=”” to it.
    in functions.php I’ve written:

    function register_menus() {
        register_nav_menus(
                array(
                    'header-menu' => __('Main Menu'),
                    'side-menu' => __('Side Menu'),
                    'footer-menu' => __('Footer Side Menu')
                )
        );
    }

    in header.php:

    wp_nav_menu(array('theme_location' => 'header-menu',
    			'container' => 'nav',
    			'menu_id' => 'mainNav',
    			'menu_class' => 'ulmenu',
    			));

    The result is that only class=”ulmenu” is applied to the <div> tag containing
    ul tag. What could possibly be the problem? I can change my CSS to make it work but I feel like if I don’t figure this problem out it will snowball in the future.

    Thanks in advance!

    NikiOnTime

Viewing 8 replies - 1 through 8 (of 8 total)
  • To apply an id and class to the container element, you should use the ‘container_id’ and ‘container_class’ options. The other options may be trumping the ‘container’ => ‘nav’ option.

    Thread Starter NikiOnTime

    (@nikiontime)

    Thanks for the fast answer but it’s still not working.
    If I write this in the header.php:

    wp_nav_menu(array('theme_location' => 'header-menu',
    			'container' => 'nav',
    			'container_id' => 'mainNav',
    			'container_class' => 'ulmenu'
    			));

    It generates the default menu:

    <div class="menu">
         <ul>
              <li class="page_item page-item-2">
                   <a href="http://localhost/CastingCartel/?page_id=2">Sample Page</a>
              </li>
         </ul>
    </div>

    Can you use pastebin.com to paste your entire header.php file and share the link, for context? Do you have a link to your site that you can share?

    Just having a conversation, and learned that wp_nav_menu() doesn’t fire if you don’t have any menus defined. Do you have any menus defined under Appearance > Menus?

    Thread Starter NikiOnTime

    (@nikiontime)

    header.php
    functions.php

    At the moment I don’t have hosting and I’m working on wamp server on my machine :/ but if you don’t see any syntax or logic errors in the source what are the possible problems ?

    Thread Starter NikiOnTime

    (@nikiontime)

    I was thinking if I should add menu items … Just a second

    Thread Starter NikiOnTime

    (@nikiontime)

    Thanks a lot marcelle42, you are right. Now it works 100% correct, all the attributes of the function are working. It was interesting that menu_class was working thou 😀

    Fantastic! Thanks for letting me know. Don’t forget to mark this as resolved!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How does wp_nav_menu work?’ is closed to new replies.