钩子文档

comments_link_feed

💡 云策文档标注

概述

comments_link_feed 是一个 WordPress 过滤器,用于在 RSS 或 Atom 等 feed 上下文中修改当前文章的评论链接。它允许开发者自定义评论部分的链接,常用于 feed 输出。

关键要点

  • 过滤器名称:comments_link_feed,用于过滤当前文章的评论永久链接。
  • 参数:接受一个字符串参数 $comment_permalink,即当前评论链接(通常附加了 '#comments')。
  • 用法:通过 add_filter() 钩子注册自定义函数,函数必须返回处理后的链接值。
  • 注意事项:自定义函数名必须唯一,不能与已声明的其他函数名冲突。

代码示例

add_filter( 'comments_link_feed', 'filter_function_name', 10 );

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

注意事项

  • 过滤器函数必须返回一个值,否则结果将为空。
  • 在 feed 上下文中使用,如 comments_link_feed() 函数输出 XML 安全的评论链接。
  • 引入版本:WordPress 3.6.0。

📄 原文内容

Filters the comments permalink for the current post.

Parameters

$comment_permalinkstring
The current comment permalink with '#comments' appended.

More Information

The comments_link_feed allows you to alter the link to the comments section of a post within the context of a feed.

When the ‘comments_link_feed’ filter is called, it is passed once parameters: the list item containing the powered by link.

<pre>add_filter( 'comments_link_feed', 'filter_function_name', 10 );

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( 'comments_link_feed', get_comments_link() ) );

Changelog

Version Description
3.6.0 Introduced.