Make WordPress Core

Opened 13 years ago

Closed 9 years ago

#19499 closed enhancement (wontfix)

Allow wp_nav_menu to return just the links (no <li> tags)

Reported by: nohalfpixels's profile nohalfpixels Owned by: nohalfpixels's profile nohalfpixels
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Menus Keywords:
Focuses: Cc:

Description

every now and again i find im in the need of the wp_nav_menu function where i only want a list if links, not the outer ul, or the li tags.

there is already scope to remove the outer ul.

but no support for removing the <li> tags from the returned results.

at present i have to do this:

$foot_nav = wp_nav_menu( array( 'container' => '', 'echo' => '0', 'theme_location' => 'footer_menu' ) );
$foot_nav2 = preg_replace( array( '#^<ul[^>]*>#', '#</ul>$#' ), '', $foot_nav );
$foot_nav2 = preg_replace( array( '#<li[^>]*>#', '#</li>$#' ), '', $foot_nav2 );
echo $foot_nav2;

this isnt very clean, it would be nice to just be able to pass a parameter the wp_nav_menu function which just returns the links.

i propose something like:

'return_links' => true,

the main reason for this is styling centered links in the footer.

its much easier to just center links than it is to center a <ul> and results in much cleaner html with less dom elements.

Change History (5)

#1 @TobiasBg
13 years ago

  • Keywords reporter-feedback added

You could use wp_get_nav_menu_items() to get an array with all the elements, without formatting. That way, you could create your own HTML around it, e.g. like they do in http://digwp.com/2011/11/html-formatting-custom-menus/

Does that maybe solve your problem?

#2 @nohalfpixels
13 years ago

thanks, that worked as well (a little better as theres no need to replace parts of the string which allways seems cleaner).

i still think this could be streamlined a little with the wp_nav_menu function.

effectivley reducing what the function returns if the flag is set.

#3 @iseulde
11 years ago

  • Keywords dev-feedback added; reporter-feedback removed

#4 @DrewAPicture
11 years ago

  • Cc xoodrew@… added

#5 @chriscct7
9 years ago

  • Keywords dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

No interest in 4+ years, and a proposed solution is above

Note: See TracTickets for help on using tickets.