Sunday, July 7, 2013

How to Remove List Elements From Output of wp_nav_menu function in wordpress

You can remove or change the <ul> tag container that you get by default with wp_nav_menu through parameters, but you can't remove the <li> elements that wrap each menu item.
Here full code of how to do it:

1st Solution (using PHP):

$menuParameters = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,

echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );

Second Solutions (using jQuery)

var path = location.href;
if ( path )
$('nav.main-menu a[href="' + path + '"]').attr('class', 'current');
Disqus Comments