How to add custom menu code in wordpress templates

  • 5 years-11 months

    How to add custom menu code in wordpress templates

    • Category : wordpress
    • Viewed : 40 times
    • Posted On :
    • Posted by : Vikas

    If you want to add custom navigation menus in your WordPress templates? By default, many WordPress themes come with pre-defined menu locations and layouts. follow this article:

    <?php $defaults = array(
        'menu'            => 'main',
        'container'       => 'div',
        'container_class' => 'navbar-collapse collapse',
        'container_id' => 'navbar',
        'menu_class'      => 'nav navbar-nav navbar-right',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>'
    );
    ?>
     
    <?php wp_nav_menu( $defaults ); ?>
    
    /* Output */
    
    <div id="navbar" class="navbar-collapse collapse">
    	<ul id="menu-main" class="nav navbar-nav navbar-right">
    		<li id="menu-item-108" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-home current-menu-item page_item page-item-2 current_page_item menu-item-108"><a href="http://www.example.com/">Home</a></li>
    	</ul>
    </div>

Report this or Ask your own question

Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.