钩子文档

comment_link

💡 云策文档标注

概述

comment_link 是一个 WordPress 过滤器,用于修改 RSS 源中评论的永久链接。它允许开发者通过自定义函数来调整评论链接的输出。

关键要点

  • comment_link 过滤器用于过滤当前评论的永久链接,主要应用于 RSS 源中。
  • 过滤器接收一个参数:$comment_permalink(当前评论链接),并必须返回处理后的链接值。
  • 使用 add_filter 钩子注册自定义函数,函数名需唯一,避免与其他函数冲突。

代码示例

add_filter( 'comment_link', 'filter_function_name', 10, 3 );

function filter_function_name( $link ) {
    // 操作评论链接
    return $link;
}

注意事项

  • 自定义函数必须返回一个值,否则输出可能为空。
  • 函数名 filter_function_name 应替换为唯一的名称,不能与已声明的其他函数重复。
  • 此过滤器在 WordPress 3.6.0 版本中引入。

📄 原文内容

Filters the current comment’s permalink.

Description

See also

Parameters

$comment_permalinkstring
The current comment permalink.

More Information

The comment_link filter provides the ability to alter the links to post comments in the RSS feed.

When the ‘comment_link’ filter is called, it is passed one parameter: the link.

add_filter( 'comment_link', 'filter_function_name', 10, 3 );

function filter_function_name( $link) {
// Manipulate comment link
return $link;
}

Where ‘filter_function_name’ is the function WordPress should call when the filter is run. Note that the filter function must return a value after it is finished processing or the result will be empty.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Source

echo esc_url( apply_filters( 'comment_link', get_comment_link( $comment ) ) );

Changelog

Version Description
3.6.0 Introduced.