Wordpress custom theme - menu not showing when called in footer.php

只愿长相守 提交于 2019-12-04 10:50:28

You have registered you two nav menus correctly. I always do that within my initial theme setup hook that gets hooked to the after_setup_theme hook. So I would do something like this in your functions.php:

function pietergoosen_theme_setup() {
  register_nav_menus( array( 
    'header' => 'Header menu', 
    'footer' => 'Footer menu' 
  ) );
 }

add_action( 'after_setup_theme', 'pietergoosen_theme_setup' );

Keep in mind, you don't have to do it this way. The following also works

register_nav_menus( array( 
        'header' => 'Header menu', 
        'footer' => 'Footer menu' 
      ) );

You should now see the two menus in the backend under "Appearance > Menus > Manage Locations" (Only if a menu exist)

For the sake of the footer menu, add the following code in your footer where you need to display the menu:

<nav id="footer-navigation" class="site-navigation footer-navigation" role="navigation">
       <?php wp_nav_menu( array( 'theme_location' => 'footer', 'menu_class' => 'nav-menu', 'fallback_cb' => false ) ); ?>
</nav>

At this stage nothing will be displayed, and I think this is where you also get stuck at. The reason for this is that there aren't any items assigned to the menu, and if there are nothing assigned to a menu, then nothing will be displayed. So we have to insert something to be displayed.

In the backend, go to "Appearance > Menus > Edit Menus". In the "Menu Name" field, enter a name for your menu and click "Create Menu". You will now be able to add the menu in the menu screen.

You can now choose items from the left hand side to insert into your menu. You can also set the location of the menu, in this case in the footer. I've selected to display the categories in the footer. Click "Save Menu" when done.

You should now see your nav menu in the front end.

You just have to add styling to your nav bar now. You will do exactly the same for the header nav menu, accept you will add the call to the menu in the header.php. I hope you find this usefull.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!