Am I using this hook incorrectly
No, you’re not.
is there another way to get the ID?
Yes, try this:
function add_menu_field( $item_id, $item, $depth, $args, $id ) {
$id2 = 0;
if ( ! $id && isset( $_GET['menu'] ) && $_GET['menu'] ) {
$id2 = absint( $_GET['menu'] );
}
elseif ( ! $id && ! isset( $_GET['menu'] ) ) {
// Get recently edited nav menu.
$id2 = absint( get_user_option( 'nav_menu_recently_edited' ) );
if ( ! is_nav_menu( $id2 ) ) {
$nav_menus = wp_get_nav_menus();
$id2 = ( ! empty( $nav_menus ) ) ? $nav_menus[0]->term_id : 0;
}
}
if ( 13 === $id2 && is_nav_menu( $id2 ) ) {
echo '<hr>add your awesome custom field here';
}
}
And that’s basically how WordPress gets the ID on the wp-admin/nav-menus.php
(Appearance → Menus) page — if there’s no selected menu ($_GET['menu']
is not set), we use the recently edited menu, if any; if none, we use the first menu in the available nav menus.
Alternate Option (use a filter to add the action)
You can use wp_edit_nav_menu_walker
to add your action to wp_nav_menu_item_custom_fields
whereby the action (i.e. the hook callback) would simply display the custom field. For example:
add_filter( 'wp_edit_nav_menu_walker', 'wpse_378190', 10, 2 );
function wpse_378190( $class, $menu_id ) {
$tag = 'wp_nav_menu_item_custom_fields';
if ( 13 === $menu_id && ! has_action( $tag, 'add_menu_field2' ) ) {
add_action( $tag, 'add_menu_field2', 10, 5 );
}
return $class;
}
// This function is hooked to wp_nav_menu_item_custom_fields and fires only if the
// menu ID is 13. So no need to check the $id and just display your custom field.
function add_menu_field2( $item_id, $item, $depth, $args, $_id ) {
$id = 13;
echo '<hr>display your awesome custom field here';
}