customization - How to extend nav-menu-item-control data in Appearance > Customize?

I have one question as for Nav Menu Items custom fields in the Appearance > Customizer screen.Since 5.4. there are 2

I have one question as for Nav Menu Items custom fields in the Appearance > Customizer screen.

Since 5.4. there are 2 new hooks:

  • wp_nav_menu_item_custom_fields - it works for Appearance > Menus properly and I have added 2 custom fields.
  • wp_nav_menu_item_custom_fields_customize_template - it works for Appearance > Customizer and adds HTML properly.

But I need to use {{data}} attribute for getting menu item attributes (my custom e.g. {{{data.visibility}}}). I want to put the same 2 custom fields to WP Customizer > Menus > Item section via this hook wp_nav_menu_item_custom_fields_customize_template and use in JS extended {{{data}}} object.

There is default {{data}} variable in JS template, it looks like this object

I have added 2 custom fields with custom data for each menu item via this hook wp_nav_menu_item_custom_fields and it works properly.

Is there a way how I can add custom properties for every menu item to {data} via PHP (add_filter) or JS hooks (wp.hooks.addFilter). I don't want to localize script and create another variable and use it in the JS template in wp_nav_menu_item_custom_fields_customize_template hook's callback.

Let me know, Thanks!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742390154a4434851.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信