Skip to content

Instantly share code, notes, and snippets.

@carwin
Created September 13, 2012 17:26
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 carwin/3716003 to your computer and use it in GitHub Desktop.
Save carwin/3716003 to your computer and use it in GitHub Desktop.
Drupal 7: Change structure of all menus from pattern [ ul > li > a ] to a valid html5 pattern [ nav > a ]
<?php
/*
* Replace all menu tree <ul> elements with <nav>.
*/
function foo_menu_tree(&$variables) {
return '<nav>' . $variables['tree'] . '</nav>';
}
/*
* Removes <li> from all menu links, leaving only <a>s.
*/
function foo_menu_link(&$variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return $output . $sub_menu;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment