Make WordPress Core

Opened 3 years ago

Last modified 2 months ago

#53214 new defect (bug)

Register Menu Item Custom Field

Reported by: mortezayung's profile mortezayung Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Menus Keywords:
Focuses: Cc:

Description

Hello, I got problem with adding custom field in menu. I set $depth == 0 for one custom field and it's work perfectly when i saved. But when user drag the menu item and make it 2nd depth, The custom field still show. It should to be hide because i just make it to show in 1nd depth not 2nd depth. I think this issue need to work or there is one solution that i don't know!

This is code

function custom_field( $item_id, $item, $depth ) {
    if ( $depth == 0 ) { ?>
        <p class="description description-wide">   
            Hello World
        </p>
    <?php }
}
add_action( 'wp_nav_menu_item_custom_fields', 'custom_field', 10, 3 );

Change History (2)

#1 @SergeyBiryukov
3 years ago

  • Component changed from General to Menus

#2 @vizvizka
2 months ago

Hello Mortezayung
In this version, the custom field will only be displayed if the depth is exactly 0. If the depth is greater than 0 (ie, the menu item is nested), the custom field will not be displayed. This should solve the issue you are encountering with the custom field appearing when the menu item is dragged to the 2nd depth.

Note: See TracTickets for help on using tickets.