Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Last active December 22, 2015 04:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpexplorer/6416006 to your computer and use it in GitHub Desktop.
Save wpexplorer/6416006 to your computer and use it in GitHub Desktop.
Add slug to menu ID for pages in WordPress menu
add_filter('nav_menu_link_attributes' , 'att_add_menu_id', 3, 10);
if ( !function_exists( 'att_add_menu_id') ) {
function att_add_menu_id($atts, $item, $args) {
if( 'page' == $item->object ){
$id = $item->object_id;
$id = 'page-'. esc_attr( basename( get_permalink( $id ) ) );
$atts['id'] = $id;
}
return $atts;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment