Skip to content

Instantly share code, notes, and snippets.

@jeremyboggs
Created August 23, 2012 18:13
Show Gist options
  • Save jeremyboggs/3439791 to your computer and use it in GitHub Desktop.
Save jeremyboggs/3439791 to your computer and use it in GitHub Desktop.
Use menu title for ID attribute instead of an number in WordPress's wp_nav_menu output
<?php
/**
* Use menu title for ID attribute instead of an number.
*
* Sanitizes the menu item's title to get a valid string for use in an ID
* attribute.
*/
function custom_nav_menu_item_id($id, $item) {
$title = sanitize_title_with_dashes($item->title);
return 'menu-item-'.$title;
}
add_filter('nav_menu_item_id', 'custom_nav_menu_item_id', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment