edit_tag_link()
云策文档标注
概述
edit_tag_link() 函数用于显示或获取标签的编辑链接,并支持格式化输出。它基于 edit_term_link() 实现,适用于 WordPress 开发者处理标签或分类法术语的编辑链接。
关键要点
- 函数接受四个参数:$link(锚文本,默认为空时显示“Edit This”)、$before(链接前内容)、$after(链接后内容)和 $tag(WP_Term 对象,默认为 null 时使用当前查询对象)。
- 内部调用 edit_term_link() 生成链接,并通过 apply_filters('edit_tag_link', $link) 钩子允许过滤锚标签。
- 函数直接输出链接,开发者可通过参数控制显示格式,例如添加前后 HTML 标签。
代码示例
// 默认用法,显示编辑标签链接
edit_tag_link();
// 自定义锚文本和包装在段落标签中
edit_tag_link('edit tag', '<p>', '</p>');注意事项
- 确保在标签页面或相关上下文中使用,否则 $tag 参数可能需要明确指定 WP_Term 对象。
- 函数输出链接,若需获取链接字符串而不直接显示,可考虑使用 edit_term_link() 替代。
原文内容
Displays or retrieves the edit link for a tag with formatting.
Parameters
$linkstringoptional-
Anchor text. If empty, default is ‘Edit This’. Default empty.
$beforestringoptional-
Display before edit link. Default empty.
$afterstringoptional-
Display after edit link. Default empty.
$tagWP_Termoptional-
Term object. If null, the queried object will be inspected.
Default:
null
Source
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
$link = edit_term_link( $link, '', '', $tag, false );
/**
* Filters the anchor tag for the edit link for a tag (or term in another taxonomy).
*
* @since 2.7.0
*
* @param string $link The anchor tag for the edit link.
*/
echo $before . apply_filters( 'edit_tag_link', $link ) . $after;
}
Hooks
- apply_filters( ‘edit_tag_link’, string $link )
-
Filters the anchor tag for the edit link for a tag (or term in another taxonomy).
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
Skip to note 3 content
Codex
Default Usage
Displays edit tag link using defaults.
Skip to note 4 content
Codex
Displays Edit Tag in Paragraph Tag
Displays edit tag link, with link text “edit tag”, in a paragraph (
) tag.
', '</p>'); ?>