Developer Snippet Diary

Wordpress nav menu: wp_nav_menu()

Syntax:

wp_nav_menu( array $args = array() ): void|string|false

Simple function call will responce:

<?php wp_nav_menu(); ?>
<div class="menu">
  <ul>
    <li class="page_item page-item-17"><a href="http://localhost/wordpress/homepage/">HomePage</a></li>
    <li class="page_item page-item-2"><a href="http://localhost/wordpress/sample-page/">Sample Page</a></li>
  </ul>
</div>

Parameters:

1. menu >>Desired menu.  Accepts a menu ID, slug, name, or object.

2. menu_class >> CSS class to use for the ul element which forms the menu. Default 'menu'.
3. menu_id  >>The ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented.

wp_nav_menu(array(
	"menu_class" =>"wp_2020",
	"menu_id" =>"wp_2020_id"
));
<div id="wp_2020_id" class="wp_2020">
<ul>/**/</ul>
</div>

4. container >>Whether to wrap the ul, and what to wrap it with. Default 'div'.
5. container_class >>  Class that is applied to the container. Default 'menu-{menu slug}-container'.
6. container_id The ID that is applied to the container.
7. container_aria_label  The aria-label attribute that is applied to the container when it's a nav element.

wp_nav_menu(array(
	"menu"=>"menu-1",
	"container" =>"nav",
	"container_class"=>"nav_is l",
	"container_id" => "nav_2020",
	"container_aria_label"=>"omg"
)); 
<nav id="nav_2020" class="nav_is l" aria-label="omg">
  <ul id="menu-menu-1" class="menu">
    <li id="menu-item-34" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-34">
      <a href="http://localhost/wordpress/" aria-current="page">Home</a>
    </li>
  </ul>
</nav>

https://developer.wordpress.org/reference/functions/wp_nav_menu/

Posted by: R GONDAL
Email: rizikmw@gmail.com