Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created custom inputs for WordPress nav-menus admin page. I've used a similar technique as is shown in this answer - by duplicating edit_custom_walker.php and adding my own fields. My custom inputs are working fine, however, they are showing on every menu on the nav-menus admin page. How do I get them to show on only menu's that are in a certain position in the theme?

The variables within Walker_Nav_Menu_Edit_Custom don't seem to reveal any information about the parent menu. Is there any way I can access the current menu that the menu item is in?

Below is the section I've added into the edit_custom_walker.php override. It is this section I want to be output conditionally depending on the menu location.

<p class="field-custom description description-wide">
    <label for="edit-menu-item-bootstrap-<?php echo $item_id; ?>">
        <?php _e( 'Bootstrap Icon' ); ?><br />
        <input type="text" id="edit-menu-item-bootstrap-<?php echo $item_id; ?>" class="widefat code edit-menu-item-custom" name="menu-item-bootstrap[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->bootstrap ); ?>" />
    </label>
</p>

If I print_r on the $item variable I get the following output

WP_Post Object ( [ID] => 1728 [post_author] => 1 [post_date] => 2014-04-07 18:43:24 [post_date_gmt] => 2014-04-07 18:43:24 [post_content] => [post_title] => [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => 1728 [to_ping] => [pinged] => [post_modified] => 2014-04-10 16:02:47 [post_modified_gmt] => 2014-04-10 16:02:47 [post_content_filtered] => [post_parent] => 0 [guid] => http://dev.mysite/?p=1728 [menu_order] => 1 [post_type] => nav_menu_item [post_mime_type] => [comment_count] => 0 [filter] => raw [db_id] => 1728 [menu_item_parent] => 0 [object_id] => 2 [object] => page [type] => post_type [type_label] => Page [url] => http://dev.mysite/?page_id=2 [title] => Sample Page [target] => [attr_title] => [description] => [classes] => Array ( [0] => ) [xfn] => [bootstrap] => ) Bootstrap Icon

None of which refers to the menu itself, or its position.

share|improve this question
    
Please edit the question to demonstrate your implementation. –  s_ha_dum Apr 10 at 16:05
    
Edited to demonstrate implementation –  tommyf Apr 10 at 16:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.