the_feed_link()
云策文档标注
概述
the_feed_link() 函数用于显示指定类型的 feed 永久链接,并输出包含锚文本的 HTML 锚标签。它接受 feed 类型参数,并可通过过滤器进行自定义。
关键要点
- 函数用于显示 feed 链接,输出格式为 <a href="...">锚文本</a>。
- 参数包括必需的锚文本 $anchor 和可选的 feed 类型 $feed(如 'rss2'、'atom',默认为 get_default_feed() 的值)。
- 使用 apply_filters('the_feed_link', $link, $feed) 钩子允许过滤输出链接。
- 相关函数包括 get_feed_link()(获取链接)、esc_url()(清理 URL)和 apply_filters()(应用过滤器)。
- 自 WordPress 3.0.0 版本引入。
代码示例
function the_feed_link( $anchor, $feed = '' ) {
$link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>';
echo apply_filters( 'the_feed_link', $link, $feed );
}
原文内容
Displays the permalink for the feed type.
Parameters
$anchorstringrequired-
The link’s anchor text.
$feedstringoptional-
Feed type. Possible values include
'rss2','atom'.
Default is the value of get_default_feed() .
Source
function the_feed_link( $anchor, $feed = '' ) {
$link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>';
/**
* Filters the feed link anchor tag.
*
* @since 3.0.0
*
* @param string $link The complete anchor tag for a feed link.
* @param string $feed The feed type. Possible values include 'rss2', 'atom',
* or an empty string for the default feed type.
*/
echo apply_filters( 'the_feed_link', $link, $feed );
}
Hooks
- apply_filters( ‘the_feed_link’, string $link, string $feed )
-
Filters the feed link anchor tag.
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |