wp_nav_menu_item_custom_fields
云策文档标注
概述
wp_nav_menu_item_custom_fields 是一个 WordPress 动作钩子,在菜单编辑器中导航菜单项的移动按钮前触发,允许开发者添加自定义字段到菜单项。
关键要点
- 钩子名称:wp_nav_menu_item_custom_fields
- 触发时机:在菜单编辑器内,导航菜单项的移动按钮前执行
- 主要用途:为菜单项添加自定义字段或扩展功能
- 引入版本:WordPress 5.4.0
- 相关函数:Walker_Nav_Menu_Edit::start_el()
参数说明
- $item_id:菜单项 ID(字符串类型)
- $menu_item:菜单项数据对象(WP_Post 类型)
- $depth:菜单项深度(整数类型)
- $args:菜单项参数对象(stdClass 或 null 类型)
- $current_object_id:导航菜单 ID(整数类型)
代码示例
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
原文内容
Fires just before the move buttons of a nav menu item in the menu editor.
Parameters
$item_idstring-
Menu item ID as a numeric string.
$menu_itemWP_Post-
Menu item data object.
$depthint-
Depth of menu item. Used for padding.
$argsstdClass|null-
An object of menu item arguments.
$current_object_idint-
Nav menu ID.
Source
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
Changelog
| Version | Description |
|---|---|
| 5.4.0 | Introduced. |
Skip to note 2 content
tripflex
Release details on this can be found here:
https://make.wordpress.org/core/2020/02/25/wordpress-5-4-introduces-new-hooks-to-add-custom-fields-to-menu-items/