Wordpress. Adding menu item manually in wp_nav_menu Wordpress. Adding menu item manually in wp_nav_menu wordpress wordpress

Wordpress. Adding menu item manually in wp_nav_menu


function add_last_nav_item($items) {  return $items .= '<li><a href="#myModal" role="button" data-toggle="modal">Contact</a></li>';}add_filter('wp_nav_menu_items','add_last_nav_item');


here is an example by changing the items_wrap.

wp_nav_menu( array( 'items_wrap' => '<ul id="%1$s" class="%2$s"><li><a href="http://www.google.com">go to google</a></li>%3$s</ul>' ) );

just took the default value and added the href.


Just for the case someone needs this:

Menu items can be added manually by applying filters:

  • wp_nav_menu_items - for all menus
  • wp_nav_menu_{$menu->slug}_items - for menu with particular slug

Also by changing items_wrap, e.g., by removing <ul> and adding it explicitly in the theme - this way you will be able to add own items.