How to add menu in WordPress theme. Add a second third or fourth menu.

This article was written by in May 31, 2015, & may not be posted on other sites!
Original source url for this article: How to add menu in WordPress theme. Add a second third or fourth menu.

How to add menu in WordPress theme. Add a second third or fourth menu.
You can have as many custom menus as you like. This is how to add menu in WordPress theme, Add a second third or fourth menu, as many as you like.

 

 How to add menu in WordPress theme.
Add a second third or fourth menu.

This is how to add menu in WordPress theme. Add a second third or fourth menu. You can have as many custom menus as you like. Follow these steps to add a custom menu in WordPress:

  1. You should always have a childtheme when altering theme files in WordPress. More on how to create a childtheme in this article.
  2. Start by adding this code in your functions.php
    //add custom menu
    register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'YOUR_THEMENAME' ),
    'secondary' => __( 'Secondary Menu', 'YOUR_THEMENAME'),
    'third-menu' => __( 'Third menu', 'YOUR_THEMENAME'),
    ) );
  3. As you can see, you can add as many menus as you like. If your WordPress theme already supports 2 menus, you can still use the code above or just write:
    //add custom menu
    register_nav_menus( array(
    'third-menu' => __( 'Third menu'),
    ) );
  4. Now you should see your custom menu in the WordPress admin under appearance > menus > manage location tab. So we have just created a position for the custom menu.
  5. Create a new menu, add some links or navigation & save it. More information on how to create a new WordPress menu in this article.
  6. Go to appearance > menus > manage location tab and select your new menu as  “Third menu”. Save.
    Add a second third or fourth menu. How to add menu in WordPress theme
  7. To print out your custom menu “Third menu” inside any WordPress theme file or template, use this php code:
    <?php //print the menu
    wp_nav_menu( array(
    'container_class' => 'custom-menu',
    'theme_location' => 'third-menu' ) );
    ?>
    Your menu will be placed inside a div with class .custom-menu.
  8. The last step is to write some CSS to style your custom menu.

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *