[wp-trac] [WordPress Trac] #53214: Register Menu Item Custom Field

WordPress Trac noreply at wordpress.org
Wed Oct 16 15:16:15 UTC 2024


#53214: Register Menu Item Custom Field
--------------------------+----------------------
 Reporter:  mortezayung   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Menus         |     Version:
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------

Comment (by devmoderation):

 Replying to [ticket:53214 mortezayung]:
 > 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 );
 >
 > }}}
 I had a similar issue with custom fields displaying at deeper menu levels,
 even though I had set $depth == 0. The custom field should only display at
 the top level (1st depth), but it continued to appear when items were
 dragged into the 2nd depth.

 To resolve this, I updated the logic so the custom field only shows at
 depth 0, and I implemented a dynamic solution to hide it when items were
 moved deeper.

 You can check my implementation on this page for
 https://www.platinumcondodeals.com/on/toronto/new-condos/ to see how it
 works.

 Let me know if you'd like further details on how I solved it!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53214#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list