How to register custom navigation menus in functions.php?
-
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_MenusBut 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.
- The topic ‘How to register custom navigation menus in functions.php?’ is closed to new replies.