Skip to content

Instantly share code, notes, and snippets.

@halgatewood
Last active December 18, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halgatewood/5786739 to your computer and use it in GitHub Desktop.
Save halgatewood/5786739 to your computer and use it in GitHub Desktop.
WP List Single Level Menu with some nice options.
// LIST MENU
function hg_get_list_menu( $menu_location = 'footer', $delimiter = "•", $class_name = "nav", $wrapper = "div", $echo = true )
{
$menu_locations = get_nav_menu_locations();
$menu_items = (array) wp_get_nav_menu_items( $menu_locations[ $menu_location ] );
$num_menu_items = count($menu_items);
if($num_menu_items >= 1)
{
$rtn .= "<{$wrapper} class=\"{$class_name}\">\n";
$end_of_loop = $num_menu_items - 1;
foreach( (array) $menu_items as $c => $menu_item )
{
$add_target = ($menu_item->target) ? " target='{$menu_item->target}'" : "";
$rtn .= " <a href=\"{$menu_item->url}\"{$add_target}>{$menu_item->title}</a>";
if($c < $end_of_loop) { $rtn .= " $delimiter \n"; }
}
$rtn .= "</{$wrapper}>\n";
}
if($echo) echo $rtn;
else return $rtn;
}
@halgatewood
Copy link
Author

I want to add highlighting one day. For now I am using this mostly in footers where it doesn't matter as much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment