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

WordPress Trac noreply at wordpress.org
Mon Jul 15 23:16:14 UTC 2024


#53214: Register Menu Item Custom Field
--------------------------+------------------------------
 Reporter:  mortezayung   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Menus         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by techfree):

 * Attachment ".diff" removed.

 diff --git a/your_file.php b/your_file.php index abcdefg..hijklmn 100644
 --- a/your_file.php +++ b/your_file.php @@ -10,6 +10,11 @@ class
 Your_Class_Name {          // Existing code to determine the depth of the
 menu item          $depth = $menu_item->menu_item_parent ?
 $menu_item->depth : 0;   +        // Check depth to display custom field
 only for top-level menu items (depth 0) +        if ($depth > 0) { +
 return $item_output; // Early return if the menu item is nested (depth >
 0) +        } +          // Add your custom field HTML here for top-level
 menu items          $custom_field = '<input type="text"
 name="custom_field" value="' . esc_attr($menu_item->custom_field) . '"
 />';   @@ -20,6 +25,7 @@ class Your_Class_Name {          // Existing code
 to append the custom field to the item output          return
 $item_output;      } +      // Additional code  }

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


More information about the wp-trac mailing list