Add custom fields to specific menus

Question

How do I add custom fields to a specific menu?

For example, I have menu "Primary" with ID 13. How do I run the wp_nav_menu_item_custom_fields hook only if ID matches the currently selected menu?

I tried getting the ID from the $id parameter of the hook, but it always returns 0. I’m trying to check the ID like this:

function add_menu_field( $item_id, $item, $depth, $args, $id ) {
    var_dump( $id );
}

add_action( 'wp_nav_menu_item_custom_fields', 'add_menu_field', 10, 5 );

This returns int(0) but my nav menu ID is 13. Am I using this hook incorrectly, or is there another way to get the ID? My goal is to put custom fields on a specific nav by checking the ID.

Thanks for any help!

0
Justin Breen 2 months 0 Answers 10 views 0

Leave an answer