钩子文档

category_list_link_attributes

💡 云策文档标注

概述

category_list_link_attributes 是一个 WordPress 过滤器钩子,用于修改分类列表项中锚点元素的 HTML 属性。它允许开发者在输出分类链接时自定义属性,如 href 和 title。

关键要点

  • 过滤器钩子:category_list_link_attributes,用于过滤分类列表项锚点元素的 HTML 属性。
  • 参数:包括 $atts(属性数组)、$category(WP_Term 对象)、$depth(深度)、$args(参数数组)和 $current_object_id(当前分类 ID)。
  • 应用场景:常用于 Walker_Category::start_el() 方法中,以增强分类列表的链接属性控制。
  • 版本:自 WordPress 5.2.0 引入。

代码示例

$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $current_object_id );

📄 原文内容

Filters the HTML attributes applied to a category list item’s anchor element.

Parameters

$attsarray
The HTML attributes applied to the list item’s <a> element, empty strings are ignored.

  • href string
    The href attribute.
  • title string
    The title attribute.

$categoryWP_Term
Term data object.
$depthint
Depth of category, used for padding.
$argsarray
An array of arguments.
$current_object_idint
ID of the current category.

Source

$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $current_object_id );

Changelog

Version Description
5.2.0 Introduced.