钩子文档

wp_get_attachment_link_attributes

💡 云策文档标注

概述

wp_get_attachment_link_attributes 是一个 WordPress 过滤器,用于修改附件链接的属性数组。它允许开发者在生成附件链接时自定义 HTML 属性。

关键要点

  • 这是一个过滤器 Hook,名称为 'wp_get_attachment_link_attributes'。
  • 它接收两个参数:$attributes(属性数组,键为属性名)和 $id(附件 ID)。
  • 主要用于 wp_get_attachment_link() 函数中,影响附件链接的生成。
  • 在 WordPress 6.2.0 版本中引入。

代码示例

$attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID );

📄 原文内容

Filters the list of attachment link attributes.

Parameters

$attributesarray
An array of attributes for the link markup, keyed on the attribute name.
$idint
Post ID.

Source

$attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID );

Changelog

Version Description
6.2.0 Introduced.