Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Last active October 29, 2024 07:15
Show Gist options
  • 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