Is it possible to add a filter for the output of nav-menu items in admin?

I want to remove certain input fields on the admin screen for nav-menus for specific menu positions. I’ve used filters to filter front-end output but not for admin output. Is there a filter available for this purpose?

For example, I want to remove the option to add a title attribute to menu items, only if the menu is used in ‘position-x’.

Filters such as nav_menu_link_attributes and wp_nav_menu_args all seem to be to filter the front end output.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

These fields are created in Walker_Nav_Menu_Edit::start_el(). To change or to remove them, create a custom walker (example for another walker) that extends Walker_Nav_Menu_Edit and uses other or less fields.

Then filter wp_edit_nav_menu_walker and return the class name of your walker.

Pseudo-code:

class Walker_Nav_Menu_Edit_Simple extends Walker_Nav_Menu_Edit {
    public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) 
    { /* Magic here. */}
}

add_filter( 'wp_edit_nav_menu_walker', function() {
    return 'Walker_Nav_Menu_Edit_Simple';
});


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x