• Resolved Aureola

    (@aureola)


    Hello,
    I’ struggling with understanding the concept of custom menus in WP. I have read numerous tutorials, but most seem to be treating much more intricate and difficult topics than the one I’m having.
    I have a simple CSS-class with some styling that I would like to apply to the main menu (and because I know I will use one more navigation later on, and it didn’t seem to add much difficulties, I register one extra menu as well in functions.php.)

    I’ve been reading through and tryied to apply the code from https://codex.www.ads-software.com/Function_Reference/register_nav_menu
    https://wordpress.stackexchange.com/questions/32186/how-to-create-a-custom-wordpress-navigation-menu-with-the-code
    and https://codex.www.ads-software.com/Navigation_Menus

    But my WP doesn’t seem to care at all; my menu is still looking like an unstyled unordered bulleted list; it just doesn’t use the class (bmenu) from my style sheet.

    Here’s my code:

    Functions.php:
    function register_my_menus() {
                register_nav_menus(
                        array(
                            'header-menu' => __('Header Menu'),
                            'extra-menu' => __('Extra Menu')
                        )
                        );
    }
            add_action('init', 'register_my_menus');

    In Header.php:

    <div id="navbar">
    
    	<?php wp_nav_menu( array( 'theme_location' =>   'header-menu' , 'container_class' => 'bmenu' )); ?>
    
            </div><!--End div id navbar -->

    And the corresponding css (an excerpt, it would be too long with all the different selectors):

    .bmenu{
    	styling...bla bla bla
    }
    .bmenu li{
    	styling... and so on
    }

    And in the back-end interface (the administration panel) I have renamed my menu to Header Menu.

    One of the tutorials I mentioned above wrote that whenever I register a new menu name, it would show up in the admin-interface, in Menu settings, but I have never seen any menus displaying there for me to select – I can but type in whatever name I want. So I don’t really get this, where I’m supposed to connect the menu in the admin panel to the registered menu name in functions.php?

    I so hope that someone could help me out. I would really like to know where I have gone wrong.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Aureola

    (@aureola)

    Now I discovered the Manage Locations tab in the admin interface, and there I was able to select my Header Menu.

    But – the output is a div class, but I want an ul class.
    So with my logic I should change the ‘container_class’ argument to something like ‘ul_class’, but there is no such thing in the documentation, and therefore certainly not a ul li class, a ul li a class, and the remaining selectors that are commonly used in a normal navigation with submenu items….

    I can’t imagine why this would be so difficult to do?

    Thread Starter Aureola

    (@aureola)

    Maybe this was not a very interesting topic, but for the sake of those who struggled with this particular difficulty I might as well provide the solution I found to this;

    I changed container_class to menu_class, after I read this in the manual:

    $menu_class
    (string) (optional) The class that is applied to the ul element which encloses the menu items. Multiple classes can be separated with spaces. Formerly known as $wrap_class.
    Default: menu

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to register custom navigation menus in functions.php?’ is closed to new replies.