函数文档

comments_link_feed()

💡 云策文档标注

概述

comments_link_feed() 函数用于以 XML 安全的方式输出当前文章的评论链接。它通过应用过滤器并转义 URL 来确保输出安全。

关键要点

  • 输出当前文章的评论链接,适用于 XML 环境(如 RSS 源)。
  • 使用 apply_filters() 应用 'comments_link_feed' 过滤器,允许开发者自定义链接。
  • 通过 esc_url() 函数转义 URL,防止 XSS 攻击,确保输出安全。
  • 内部调用 get_comments_link() 获取评论链接,并附加 '#comments'。
  • 自 WordPress 3.0.0 版本引入,3.6.0 版本添加了过滤器。

📄 原文内容

Outputs the link to the comments for the current post in an XML safe way.

Source

function comments_link_feed() {
	/**
	 * Filters the comments permalink for the current post.
	 *
	 * @since 3.6.0
	 *
	 * @param string $comment_permalink The current comment permalink with
	 *                                  '#comments' appended.
	 */
	echo esc_url( apply_filters( 'comments_link_feed', get_comments_link() ) );
}

Hooks

apply_filters( ‘comments_link_feed’, string $comment_permalink )

Filters the comments permalink for the current post.

Changelog

Version Description
3.0.0 Introduced.