page_menu_link_attributes
云策文档标注
概述
page_menu_link_attributes 是一个 WordPress 过滤器,用于修改页面菜单项中锚点元素的 HTML 属性。它允许开发者在生成菜单时自定义链接属性,如 href 或 aria-current。
关键要点
- 过滤器名称:page_menu_link_attributes
- 主要用途:过滤页面菜单项锚点元素的 HTML 属性
- 参数包括:$atts(属性数组)、$page(WP_Post 对象)、$depth(深度)、$args(参数数组)、$current_page_id(当前页面 ID)
- 引入版本:WordPress 4.8.0
代码示例
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );注意事项
在 Walker_Page::start_el() 方法中使用,用于输出树中当前元素的开始部分。空字符串属性会被忽略。
原文内容
Filters the HTML attributes applied to a page menu item’s anchor element.
Parameters
$attsarray-
The HTML attributes applied to the menu item’s
<a>element, empty strings are ignored.hrefstringThe href attribute.aria-currentstringThe aria-current attribute.
$pageWP_Post-
Page data object.
$depthint-
Depth of page, used for padding.
$argsarray-
An array of arguments.
$current_page_idint-
ID of the current page.
Source
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );
Changelog
| Version | Description |
|---|---|
| 4.8.0 | Introduced. |