Title: Adding custom fields to WordPress nav menus
Last modified: August 30, 2016

---

# Adding custom fields to WordPress nav menus

 *  [rerraw](https://wordpress.org/support/users/rerraw/)
 * (@rerraw)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/adding-custom-fields-to-wordpress-nav-menus/)
 * I’m added new custom checkbox field to the nav menu items. the check box added
   without any problem when i check it it’s work but when i want uncheck it not 
   work and stay in checked state.
    the code below show the steps to create the 
   checkbox custom field> it is contains any error?
 * **first i created check box key within database**
 *     ```
       function YPE_setup_custom_fields($item) {
           $item->divider = get_post_meta($item->ID, '_menu_item_divider', true);
       }
       add_filter('wp_setup_nav_menu_item', 'YPE_setup_custom_fields');
       ```
   
 * **then i created the update value for it**
 *     ```
       function YPE_update_custom_fields($menu_id, $menu_item_db_id, $menu_item_data) {
           if (is_array($_REQUEST['menu-item-divider'])) {
               $YPE_divider_value = $_REQUEST['menu-item-divider'][$menu_item_db_id];
               update_post_meta($menu_item_db_id, '_menu_item_divider', $YPE_divider_value);
       }
       add_action('wp_update_nav_menu_item', 'YPE_update_custom_fields', 10, 3);
       ```
   
 * **then i created the new (Walker_Nav_Menu_Edit_Custom) class**
 *     ```
       function YPE_edit_custom_walker($walker, $item_id) {
           return 'Walker_Nav_Menu_Edit_Custom';
       }
       add_filter('wp_edit_nav_menu_walker', 'YPE_edit_custom_walker', 10, 2);
       ```
   
 * **then i added the check box within my new class (Walker_Nav_Menu_Edit_Custom)**
 *     ```
       <p class="field-link-divider description">
           <label for="edit-menu-item-divider-<?php echo $item_id; ?>">
               <input type="checkbox" id="edit-menu-item-divider-<?php echo $item_id; ?>" value="_blank" name="menu-item-divider[<?php echo $item_id; ?>]"<?php checked( $item->divider, '_blank' ); ?> />
               <?php _e( 'Show divider' ); ?>
           </label>
       </p>
       ```
   

Viewing 1 replies (of 1 total)

 *  [JacobTheDev](https://wordpress.org/support/users/revxx14/)
 * (@revxx14)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-custom-fields-to-wordpress-nav-menus/#post-6895075)
 * Hey, did you ever figure this out? I’m trying to do something similar.

Viewing 1 replies (of 1 total)

The topic ‘Adding custom fields to WordPress nav menus’ is closed to new replies.

## Tags

 * [menu](https://wordpress.org/support/topic-tag/menu/)
 * [nav menu](https://wordpress.org/support/topic-tag/nav-menu/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [JacobTheDev](https://wordpress.org/support/users/revxx14/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/adding-custom-fields-to-wordpress-nav-menus/#post-6895075)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
